Blogger Information
Blog 5
fans 0
comment 0
visits 3079
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Go基本语法
echo
Original
486 people have browsed it

变量、常量

Go语言中的变量必须先声明在使用(跟php,python不一样)

声明变量

var 变量名 变量类型

  1. package main
  2. import "fmt"
  3. // 声明变量 推荐使用驼峰命名
  4. // var name string
  5. // var age int
  6. // var isOpen bool
  7. // 批量声明
  8. var (
  9. name string // ""
  10. age int // 0
  11. isOpen bool // false
  12. )
  13. func main() {
  14. // 非全局变量必须使用
  15. var s string
  16. s = "s"
  17. fmt.Printf("s = %s", s)
  18. }

var a = “aaaa” // 类型推导 根据值判断变量类型
b := “bbb” // 简短声明,只能在函数内使用
// 匿名变量 用_代替 多用于占位 忽略值

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post