• 1.go变量


    package main
    
    import "fmt"
    
    func main() {
    	//	Declare variables that are set to their zero value.
    	// 0 值
    	var a int
    	var b string
    	var c float64
    	var d bool
    	fmt.Printf("var a int 	 %T [%v]
    ", a, a)
    	fmt.Printf("var b string 	 %T [%v]
    ", b, b)
    	fmt.Printf("var c float64 	 %T [%v]
    ", c, c)
    	fmt.Printf("var d bool 	 %T [%v]
    ", d, d)
    	/*
    
    		var a int 	 int [0]
    		var b string 	 string []
    		var c float64 	 float64 [0]
    		var d bool 	 bool [false]
    
    	*/
    
    	fmt.Printf("
    ")
    
    	// Declare variables and initialize.
    	// Using the short variable declaration operator.
    	//	 初始值, 使短声明
    	aa := 10
    	bb := "hello"
    	cc := 3.14159
    	dd := true
    
    	fmt.Printf("aa := 10 	 %T [%v]
    ", aa, aa)
    	fmt.Printf("bb := "hello" 	 %T [%v]
    ", bb, bb)
    	fmt.Printf("cc := 3.14159 	 %T [%v]
    ", cc, cc)
    	fmt.Printf("dd := true 	 %T [%v]
    ", dd, dd)
    
    	/*
    		aa := 10 	 int [10]
    		bb := "hello" 	 string [hello]
    		cc := 3.14159 	 float64 [3.14159]
    		dd := true 	 bool [true]
    
    	*/
    
    	//	Specify type and perform a conversion.
    	// 类型转换
    	aaa := int32(10)
    	fmt.Printf("aaa := int32(10) 	 %T [%v]
    ", aaa, aaa)
    	/*
    		aaa := int32(10) 	 int32 [10]
    	*/
    
    }
    
    /*
    	Zero Values:
    	Type Initialized Value
    	Boolean false
    	Integer 0
    	Floating Point 0
    	Complex 0i
    	String "" (empty string)
    	Pointer nil
    */
    

    练习

    // All material is licensed under the Apache License Version 2.0, January 2004
    // http://www.apache.org/licenses/LICENSE-2.0
    
    // Declare three variables that are initialized to their zero value and three
    // declared with a literal value. Declare variables of type string, int and
    // bool. Display the values of those variables.
    //
    // Declare a new variable of type float32 and initialize the variable by
    // converting the literal value of Pi (3.14).
    package main
    
    // main is the entry point for the application.
    func main() {
    
    	// Declare variables that are set to their zero value.
    	var a1 int
    	var b1 string
    	var c1 bool
    
    	// Display the value of those variables.
    	print("a1:", a1, " b1:", b1, " c1:", c1)
    
    	// Declare variables and initialize.
    	// Using the short variable declaration operator.
    	a11 := 111
    	b11 := "what"
    	c11 := true
    
    	// Display the value of those variables.
    	println("a11-->", a11, " b11-->", b11, " c11-->", c11)
    
    	// Perform a type conversion.
    	Pi := float32(3.14)
    
    	// Display the value of that variable.
    	println(Pi)
    }
    
  • 相关阅读:
    最容易忽略的的前端面试基础题目
    关于浮动宽度不够掉盒子的问题解决方法
    最容易忽略的的前端面试基础题目
    构造字典
    Python数据类型---字典
    Python数据类型---列表
    Python数据类型---字符串
    我要学习Python
    [IT练习册]Python练习项目 思路
    【CTF】后续深入学习内容
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8577056.html
Copyright © 2020-2023  润新知