当前位置:网站首页>[Yugong series] go teaching course 005 variables in July 2022
[Yugong series] go teaching course 005 variables in July 2022
2022-07-07 04:53:00 【InfoQ】
One 、 Variable
1. Definition of variables
2. Role of variables
3. Variable declaration and initialization
3.1 Declaration of variables
fmt.Println(a)
3.2 Initialization of a variable
var age int=10
3.3 The assignment of a variable
var age,num int
age=10
num=20
fmt.Println(age,num) //10,20
var age int =10
var num int
num=age
fmt.Println(num) //10
3.4 Case study : Exchange the values of two variables
package main
import "fmt"
func main(){
a := 1
b := 5
var t int
t = a
a = b
b = t
fmt.Println("a = ", a, "b = ", b )
}
package main
import "fmt"
func main(){
a := 1
b := 5
a = a + b
b = a - b
a = a - b
fmt.Println("a = ", a, "b = ", b )
}
package main
import "fmt"
func main() {
a := []int{1, 2}
b := []int{3, 4, 5}
a, b = b, a
fmt.Println(`a:`, a)
fmt.Println(`b:`, b)
}
summary
- Variable declarations :var Variable name variable type
- Declare multiple variables :var Variable name 1, Variable name .... type
- Declare an integer variable , The default value is 0
- Output statements can use only one Println function , The middle part is separated by English half width commas !
- You can set the value of a variable , Assign to another variable , And the old value in the variable is overwritten by the new value .
边栏推荐
- 微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
- Vscode automatically adds a semicolon and jumps to the next line
- Tiktok may launch an independent grass planting community platform: will it become the second little red book
- What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
- Local tool [Navicat] connects to remote [MySQL] operation
- How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
- JS also exports Excel
- A picture to understand! Why did the school teach you coding but still not
- Markdown编辑器
- 过气光刻机也不能卖给中国!美国无理施压荷兰ASML,国产芯片再遭打压
猜你喜欢
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
Local tool [Navicat] connects to remote [MySQL] operation
In depth analysis of kubebuilder
The request request is encapsulated in uni app, which is easy to understand
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
NTU notes 6422quiz review (1-3 sections)
树与图的深度优先遍历模版原理
Common Oracle SQL statements
随机推荐
Flex layout and usage
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
How does vscade use the built-in browser?
Data security -- 12 -- Analysis of privacy protection
A picture to understand! Why did the school teach you coding but still not
【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
Some understandings about 01 backpacker
Flask项目使用flask-socketio异常:TypeError: function() argument 1 must be code, not str
[hand torn STL] list
JS form get form & get form elements
【736. Lisp 语法解析】
架构实战训练营|课后作业|模块 6
acwing 843. n-皇后问题
为什么很多人对技术债务产生误解
深入解析Kubebuilder
Acl2022 | decomposed meta learning small sample named entity recognition
Run the command once per second in Bash- Run command every second in Bash?
System framework of PureMVC
DFS和BFS概念及实践+acwing 842 排列数字(dfs) +acwing 844. 走迷宫(bfs)
A detailed explanation of head pose estimation [collect good articles]