A. Naming function
Parameters none Return value None
方式一
func 函数名()(){}
方式二
func 函数名(){}
No argument there is a return value
方式一
func 函数名()(返回参数1的数据类型1){}
Fixed length parameters, return value
func关键字 函数名(参数1 类型,参数2 类型)(返回参数1的数据类型1,返回参数2的数据类型){}
//如果参数1与参数2的数据类型相同
func关键字 函数名(参数1,参数2 类型)(返回参数1的数据类型1,返回参数2的数据类型){}
//如果参数1与参数2的数据类型为int,参数3数据类型为uint
func关键字 函数名(参数1,参数2 int,参数3 uint)(返回参数1的数据类型1,返回参数2的数据类型){}
Fixed-length parameters, no return value
//方式一
func关键字 函数名(参数1 类型,参数2 类型){}
//方式二
func关键字 函数名(参数1 类型,参数2 类型)(){}
Variable-length parameters
//方式一
func关键字 函数名(不定长参数1... 类型){}
//有定长参数和不定长参数
func关键字 函数名(定长参数 类型,不定长参数1... 类型){}
//不定长的参数必须写在定长的参数后面
//不定长参数所有数据类型
func关键字 函数名(不定长参数1... interface{}){}
Anonymous function
//定义
func (参数一,参数二)(返回参数1的数据类型1){return 1 }
//定义+调用
func (参数一,参数二)(返回参数1的数据类型1){return 1 }()
Two. Notes
- Because it is compiled with the main function inside the main language used does not need to pay attention to the relationship has
没有关键字传参
没有默认参数
- Divisors function is not indented, but still have to pay attention to the layout looks very much otherwise it will indent
丑