当前位置:网站首页>Go basic constant definition and use
Go basic constant definition and use
2022-07-02 23:15:00 【Yi Yue Wang Chao】
Definition and use of basic constants :
Constants define code instances
package main func main() { // Constant definition : Can be called , It cannot be modified const PI = 3.1415926 r := 2.0 println(2*PI*r) // Set law defines constants const ( MALE = 1 FEMALE = 2 ) println(MALE, FEMALE) // Constant group definition considerations , If the type and initial value are not specified , Keep consistent with its previous line const ( x int = 16 y s string = "goho" z ) println(x, y, s, z) // Constant considerations : // 1. The data type of a constant can be Boolean 、 Numbers and strings // 2. Constants that have not been used will not report errors when compiling // 3. Constant group definition considerations , If the type and initial value are not specified , Keep consistent with its previous line }
Running results :
iota Constant counter :
itoa
yes go Language Constant automatic generator in , It doesn't follow c Language like enumerations can be generated implicitly , You must explicitly specify , The specific syntax is as follows :
- Constant combination assignment ,
iota
The default from the 0 Start , Add one more each time : - Every time
iota
Meet a new oneconst
, It will reset to 0: - Assign values to the same line ( List assignment ),
itoa
The value of does not change :
go Definition
package main func main() { // const Of iota Constant counter , // Constant definitions without expressions reuse the previous line of expressions const( a = iota // The default from the 0 Start b c ) println("iota Constant :", a, b, c) // each const Of iota Constant modules do not interfere with each other const ( x = iota y z ) println(" each iota Constant modules do not interfere with each other :", x, y, z) // How to learn from other non 0 How about the number // Constant definitions without expressions reuse the previous line of expressions // Pay attention to the meaning of adding one line by line const ( aa, bb = iota, iota cc = 10 dd, ee = iota, iota ) println(aa, bb, cc, dd, ee) }
Running results :
边栏推荐
- [hardware] origin of standard resistance value
- Alibaba cloud award winning experience: how to use polardb-x
- 严守工期,确保质量,这家AI数据标注公司做到了!
- Xshell configuration xforward forwarding Firefox browser
- Submit code process
- Value sequence < detailed explanation of daily question >
- Win11如何开启目视控制?Win11开启目视控制的方法
- xshell配置xforward转发火狐浏览器
- RecyclerView结合ViewBinding的使用
- Eight honors and eight disgraces of the programmer version~
猜你喜欢
Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
Why does RTOS system use MPU?
Xshell configuration xforward forwarding Firefox browser
Chow-Liu Tree
MarkDown基本语法
[hardware] origin of standard resistance value
RecyclerView结合ViewBinding的使用
地平线2022年4月最新方案介绍
[redis notes] compressed list (ziplist)
Redis 过期策略+conf 记录
随机推荐
Lambda表达式:一篇文章带你通透
归并排序详解及应用
严守工期,确保质量,这家AI数据标注公司做到了!
解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错
高数有多难?AI 卷到数学圈,高数考试正确率 81%!
golang中new与make的区别
Sword finger offer II 099 Sum of minimum paths - double hundred code
20220527_ Database process_ Statement retention
潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
深度剖析数据在内存中的存储----C语言篇
阿里云有奖体验:如何使用 PolarDB-X
20220527_数据库过程_语句留档
Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
[redis notes] compressed list (ziplist)
Alibaba cloud award winning experience: how to use polardb-x
Set right click to select vs code to open the file
移动端 1px 像素兼容性问题,实现1px 边框
门牌制作 C语言
Win11如何开启目视控制?Win11开启目视控制的方法
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code