当前位置:网站首页>How to use iota keyword in go language
How to use iota keyword in go language
2022-07-19 03:29:00 【Yisu cloud】
Go In language Iota How to use keywords
This article mainly explains “Go In language Iota How to use keywords ”, The explanation in the text is simple and clear , Easy to learn and understand , Next, please follow Xiaobian's ideas and go deeper slowly , Study and learn together “Go In language Iota How to use keywords ” Well !
One 、 Review constants
mention Iota This keyword , You have to review Go Constant of language .
1.Go Language constants are generally used const Statement
2.Go Language constants can only be Boolean 、 Digital ( Integer type 、 Floating point and complex Numbers ) And string
3.Go A constant of a language may not specify a type , By the compiler itself , Like the one below 【string】 It's something you can't write ( Also known as Implicit type definition )
const s string = "constant"
4. Constants cannot be changed while the program is running
Two 、Iota Usage of
Through a specific example , Look at iota Characteristics of . Example: what is the value of each constant in the output of the following code ?
package IotaDemoimport ( "fmt")const( a = iota b c)const( m=1<<iota n=2<<iota x=10 y = iota z=iota>>1 o)func IotaTest() { fmt.Println("a=",a) fmt.Println("b=",b) fmt.Println("c=",c) fmt.Println("m=",m) fmt.Println("n=",n) fmt.Println("x=",x) fmt.Println("y=",y) fmt.Println("z=",z) fmt.Println("o=",o)}give the result as follows :
a= 0
b= 1
c= 2
m= 1
n= 4
x= 10
y= 3
z= 2
o= 2
The above results show that iota Characteristics of , as follows :
iota Can only be used in const Limited , Counter equivalent to a constant
iota Equivalent to an enumeration value , The default from the 0 Start , In a const in , Will be carried out in +1, for example a、b、c You can see it
iota Not because const Fixed value assigned to , No more ,const Every constant in +1, for example x and y ,y Not because x To be an assignment 10, Namely 2, It is 3
Enter a new one at a time const,iota It will start again
Add knowledge points of shift operation :
about Go Linguistic <<( Move right ) and >>( Move left ) operation , The key points are :
1. First convert the shifted value to 2 Base number , Moving to the right is the high complement 0, Shift left is the low fill 0
2. To the right of the operator is the number of digits to be moved , On the left is the value to be moved ,
for example 1<<3 Is to put 1 Move to the left 3 position , namely 00000001 Move left 3 position Turn into 00000100 Namely 4
3<<1 Is to put 3 Move to the left 1 by , namely 00000011 Move left 1 by Turn into 00000110 Namely 6
Thank you for reading , That's all “Go In language Iota How to use keywords ” Content. , After learning this article , I'm sure you're right Go In language Iota I have a deeper understanding of how to use keywords , The specific use needs to be verified by practice . This is billion speed cloud , Xiaobian will push you articles with more relevant knowledge points , Welcome to your attention !
边栏推荐
- Theoretical basis of doubledqn and its code implementation [pytoch + pendulum-v0]
- Obvious things
- Yolov5 ncnn reasoning
- Monte Carlo based reinforcement learning method [with code implementation]
- Net SNMP development I
- leetcode:50. Pow(x, n)
- JDBC connection to MySQL database
- Affine transformation implementation
- Code demonstration of fcos face detection model in openvino
- Is there really no way out for functional testing? 10K capping is never a joke
猜你喜欢

ES6 learning notes - brother Ma at station B

Basic IDL content of note 1: common data types_ Create array_ Type conversion_ Print output_ Basic operation_ Relational operation

MySQL optimized index

ubuntu清除cuda缓存

Is there really no way out for functional testing? 10K capping is never a joke

Es6 notes d'étude - station B Xiao Ma Ge

【剑指Offer】31-35题(判断一个序列是否是栈的出栈序列之一,层序打印二叉树以及分行打印、每行逆着打印),判断序列是否是二叉搜索树的后序遍历路径,二叉树找一条权值为K的路径,复制复杂链表

leetcode162. 寻找峰值

Polynomial interpolation fitting (I)

Chengxin University envi_ The second week of IDL experiment content: extract aod+ in all MODIS aerosol products for detailed analysis
随机推荐
It's good to take more exercise
Win10 onedrive failure reinstallation
367. Effective complete square (necessary for entry)
Leetcode: subsequence problem in dynamic programming
[MCU simulation] (XX) org - set start address
About 1000base-t1 1000Base-TX and 100base-t1
Rhce8 Study Guide Chapter 2 use of basic commands
Configure high availability using virtual ip+kept
Binary search (leetcode704. very simple and necessary)
二分查找(leetcode704.很简单必会的)
Pytorch best practices and code templates
A Youku VIP member account can be used by several people to log in at the same time. How to share multiple people using Youku member accounts?
Paper reading: u-net++: redesigning skip connections to exploit multiscale features in image segmentation
Can't access this website can't find DNS address DNS_ PROBE_ What about started?
MySQL multi table query
洛谷每日三题之第三天(第四天补做)
我最高产的EasyPyPI又双叒叕更新了!v1.4.0发布
We should increase revenue and reduce expenditure
SQL classic exercises (x30)
Graphql first acquaintance