当前位置:网站首页>Go learning notes (5) basic types and declarations (4)
Go learning notes (5) basic types and declarations (4)
2022-07-01 05:01:00 【Raring_ Ringtail】

Today is the Lantern Festival , Have you eaten glutinous rice balls ?
Go on go Basic type .
Constant
Like any other language ,go Constants can also be defined .
const x int64 = 100
Basically and var It's similar to .
stay go In language ,const It is equivalent to naming literal quantity , It can only save values that the compiler can get at compile time . There are about the following categories :
- Numerical literals
trueandfalse- character string
- character
- Built in functions
complex、real、imag、lenAndcap - An expression that can determine the value at compile time
go There is no guarantee that a value calculated at run time will remain unchanged .
Typed and untyped constants
Constants can be typed or untyped .
Typeless constants are just like literal quantities , It has no type itself , But if you can't infer the type when using , Then it will be the default type of its literal .
const a = 123
var b int = a
var c float64 = a
d := a
Typed constants can only be evaluated and assigned to variables of the same type .
Unused variables
go There is a very strong grammatical rule ,go Require every defined local variable Must be used . Otherwise, a compilation error will be reported . This can greatly reduce code redundancy , Improve code quality .
however go Compiler checking is relatively loose , As long as the variable is read once, no error will be reported , Even if you assign a value to a variable but don't use it later .
func main(){
x:=123
fmt.Println(x)
x=10
}
If you want to find such problems, you can use golangci-lint
go Languages can define unused Package level variables .
go Language allows creation of Unused constants .
Welcome to my WeChat official account. Notes on Jiangda
边栏推荐
- Like cloud functions
- 缓冲流与转换流
- 神经网络-非线性激活
- [FTP] the solution to "227 entering passive mode" during FTP connection
- Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Print stream and system setout();
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
- 【暑期每日一题】洛谷 P1629 邮递员送信(未完待续...)
- LeetCode_ 66 (plus one)
猜你喜欢
随机推荐
Global and Chinese markets of superconductor 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode_53(最大子数组和)
Matters behind the construction of paint testing laboratory
FileOutPutStream
STM32 extended key scan
点赞的云函数
JS to solve the problem of floating point multiplication precision loss
pytorch神经网络搭建 模板
How to hide browser network IP address and modify IP internet access?
Pytoch (II) -- activation function, loss function and its gradient
Leecode record 1351 negative numbers in statistical ordered matrix
最长递增子序列及最优解、动物总重量问题
【FTP】FTP连接时出现“227 Entering Passive Mode”的解决方法
Print stream and system setout();
STM32扩展板 数码管显示
How to use common datasets in pytorch
Buffer stream and transform stream
1076 Forwards on Weibo
Leetcode1497- check whether array pairs can be divided by K - array - hash table - count
复制宝贝提示材质不能为空,如何解决?
![[NLP Li Hongyi] notes](/img/8e/a51ca5eee638facd54270fb28d2fce.jpg)








