Golang 常量

package main

import "fmt"

// const 常量: 不允许修改值
func main() {
	const name string = "China"
	fmt.Println("name is ", name)
	const (
		//BEIJING  = iota //iota = 0	,iota只能配合const()一起使用,变量无法使用;
		BEIJING  = 10 * iota //iota第一个 是0
		SHANGHAI             // iota = 1	第二个是1
		SHENZHEN             // iota = 2
	)
	fmt.Println("BEIJING = ", BEIJING)
	fmt.Println("SHANGHAI = ", SHANGHAI)
	fmt.Println("SHENZHEN = ", SHENZHEN)
	const (
		a, b = iota + 1, iota + 2 //iota = 0, a = 1, b = 2
		c, d                      // iota = 1, c = iota + 1 = 2,  d = iota + 2 = 3
		e, f                      // iota = 2, e = 3, f = 4

		g, h = iota * 2, iota * 3 // iota =3 , g = 6, h = 9
		i, j                      // iota = 4, i = 8, j = 12

	)
	fmt.Println("a = ", a, "b = ", b)
	fmt.Println("c = ", c, "d = ", e)
	fmt.Println("e = ", e, "f = ", f)
	fmt.Println("g = ", g, "h = ", h)
	fmt.Println("i = ", i, "j = ", j)
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值