当前位置:网站首页>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
边栏推荐
- Basic skeleton of neural network nn Use of moudle
- STM32 photoresistor sensor & two channel AD acquisition
- AcWing 884. Gauss elimination for solving XOR linear equations
- 每日一题-LeetCode1175-质数排列-数学
- Data loading and preprocessing
- STM32 expansion board digital tube display
- Global and Chinese market for kitchen range hoods 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
- HCIP Day13
- 分布式锁的实现
猜你喜欢

Technology sharing | broadcast function design in integrated dispatching

Daily question -leetcode1175- permutation of prime numbers - Mathematics

Fitness without equipment

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

神经网络-最大池化的使用

LeetCode316-去除重复字母-栈-贪心-字符串

STM32 expansion board digital tube display

STM32 photoresistor sensor & two channel AD acquisition

Neural network - nonlinear activation

最长递增子序列及最优解、动物总重量问题
随机推荐
分布式-总结列表
洗个冷水澡吧
Use of dataloader
C - detailed explanation of operators and summary of use cases
pytorch中常用数据集的使用方法
Use of STM32 expansion board temperature sensor and temperature humidity sensor
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
Single page application
Character input stream and character output stream
分布式全局唯一ID解决方案详解
FileOutPutStream
线程类的几大创建方法
Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
[daily question in summer] Luogu p7222 [rc-04] informatics competition
[daily question in summer] Luogu p2026 find the analytic formula of primary function
常用的Transforms中的方法
AcWing 885. Find the combination number I (recursive preprocessing)
Detailed explanation of distributed global unique ID solution
RuntimeError: “max_pool2d“ not implemented for ‘Long‘