当前位置:网站首页>[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 .
边栏推荐
- Factor analysis r practice (with R installation tutorial and code)
- What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
- 窗口可不是什么便宜的东西
- Basic idea of counting and sorting
- Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
- 掌握软件安全测试方法秘笈,安全测试报告信手捏来
- JS variable
- Run the command once per second in Bash- Run command every second in Bash?
- How does vscade use the built-in browser?
- Vscode 如何使用内置浏览器?
猜你喜欢
为什么很多人对技术债务产生误解
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
Meow, come, come: do you really know if, if else
Oracle -- 视图与序列
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
程序员上班摸鱼,这么玩才高端!
Basic idea of counting and sorting
Introduction to namespace Basics
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
acwing 843. N-queen problem
随机推荐
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
Vscode 如何使用内置浏览器?
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
未婚夫捐5亿美元给女PI,让她不用申请项目,招150位科学家,安心做科研!
计数排序基础思路
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
Oracle - views and sequences
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
Canteen user dish relationship system (C language course design)
JS variable
MySQL split method usage
sscanf,sscanf_ S and its related usage "suggested collection"
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
Tiktok may launch an independent grass planting community platform: will it become the second little red book
使用Thread类和Runnable接口实现多线程的区别
How to conduct website testing of software testing? Test strategy let's go!
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
PLC模拟量输出 模拟量输出FB analog2NDA(三菱FX3U)
Poor math students who once dropped out of school won the fields award this year