Go-常量-const
常量:只能读,不能修改,编译前就是确定的值
关键字: const
常量相关类型:int8,16,32,64 float32,64 bool string 可计算结果数学表达式
常量方法 iota
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package main import "fmt" func main() { const name = "BeinMenChuiXue" fmt.Println(name) const ( homeAddr = "earth" nickName = "WeiLaiShiXuePai" ) fmt.Println(homeAddr, nickName) const ( zero = iota one two = iota three ) fmt.Println(zero, one, two, three) const ( first = iota second ) fmt.Println(first, second) const ( student = "Golang" teacher parents = "S" children ) fmt.Println(student, teacher, parents, children) } |
观察输出结果,得出以下有关常量特性
1. 定义多个常量推荐使用括号
2. iota每往下一行自增1并赋值给这一行的常量,遇到下一个const重新从0开始
3. 常量未赋值,往上找最近有值的常量并赋值给自己
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2020-11-23 logstash实现敏感信息脱敏及超长字符截取
2018-11-23 Hadoop原生态版安装