The default rule GO program design and keyword

The default rule GO program design and keyword

Go reason so simple, because it has some default behavior: variable start with a capital letter is exportable, that is, other packages can read, is a common variable; lowercase letters is the beginning of the non-exportable, private variable. Functions that begin with a capital letter is the same, the equivalent class in the public keyword with public functions; beginning with a lowercase letter is to have private keyword private functions.

Go is also reflected in only 25 key
programs declare class: import, package
program entities declare and define classes: chan, const, func, interface , map, struct, type, var
program flow control class: go, select, break, case, continue, default, defer, else, fallthrough, for, goto, if, range, return, switch

The following are some of the usage of keywords

  1. var and const : used to declare variables and constants
const identifier [type] = value  //常量的定义格式

What way can also be used to define constants

const (
	a = iota    //iota为枚举类型
	b = iota
	c = iota)
  1. the Map : the equivalent of the dictionary in python
//两种定义方式
var numbers map[string] int  //numbers := make(map[string]int) 
numbers["one"] = 1  //赋值
numbers["ten"] = 10 //赋值 
Published 33 original articles · won praise 1 · views 2295

Guess you like

Origin blog.csdn.net/qq_40805620/article/details/99697015