当前位置:网站首页>【愚公系列】2022年7月 Go教学课程 005-变量
【愚公系列】2022年7月 Go教学课程 005-变量
2022-07-06 22:33:00 【InfoQ】
一、变量
1.变量的定义
2.变量的作用



3.变量的声明和初始化
3.1 变量的声明

fmt.Println(a)
3.2 变量的初始化
var age int=10

3.3 变量的赋值
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 案例:交换两个变量的值
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)
}
总结
- 变量声明:var变量名称变量类型
- 声明多个变量:var变量名称1,变量名称....类型
- 声明整型变量,默认值为0
- 输出语句可以只使用一个Println函数,中间用英文半角逗号进行分割!
- 可以将一个变量的值,赋值给另外一个变量,并且变量中原有的旧值被新值所覆盖。
边栏推荐
- Flex layout and usage
- 为什么很多人对技术债务产生误解
- 架构实战训练营|课后作业|模块 6
- Depth first traversal template principle of tree and graph
- Acl2022 | decomposed meta learning small sample named entity recognition
- Oracle - views and sequences
- Two divs are on the same line, and the two divs do not wrap "recommended collection"
- A row of code r shows the table of Cox regression model
- 【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
- R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
猜你喜欢

JS also exports Excel

R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标

Introduction to namespace Basics

Have you got the same "artifact" of cross architecture development praised by various industry leaders?

Basic idea of counting and sorting

【736. Lisp 语法解析】

Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence

Meow, come, come: do you really know if, if else

mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi

当 Knative 遇见 WebAssembly
随机推荐
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
5G VoNR+之IMS Data Channel概念
01机器学习相关规定
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
一度辍学的数学差生,获得今年菲尔兹奖
Intel David tuhy: the reason for the success of Intel aoten Technology
Oracle -- 视图与序列
Acl2022 | decomposed meta learning small sample named entity recognition
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
namespace基础介绍
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Vscode automatically adds a semicolon and jumps to the next line
Meow, come, come: do you really know if, if else
A simple and beautiful regression table is produced in one line of code~
MySQL null value processing and value replacement
Is there any way to bookmark the code in the visual studio project- Is there a way to bookmark code in a Visual Studio project?
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Depth first traversal template principle of tree and graph
当 Knative 遇见 WebAssembly