当前位置:网站首页>2-GO variable operation
2-GO variable operation
2022-04-23 14:40:00 【Endless character】
Catalog
One 、 Introduction of variables
- What is a variable : Variables are used to describe the data storage space in the computer
- Role of variables : Is to save data in computer memory
- Declaration of variables :
var Variable name type
package main
import "fmt"
func main() {
var age int
var num, sum int
fmt.Println(age)
fmt.Println(num)
fmt.Println(sum)
}
- Variable initialization : You can assign values to variables when you define them , This process initializes variables
package main
import "fmt"
func main() {
var age int = 10
var num int = 20
fmt.Println(age, num)
}
- Variable assignment : After the variable is defined , And assign values to variables , That is, declaration before assignment
func main() {
var a int = 10
var b int
b = a
fmt.Println(b)
}
- Case study : In exchange for 2 Values of variables
func main() {
var num1 int = 10
var num2 int = 20
var temp int
temp = num1
num1 = num2
num2 = temp
fmt.Println(num1, num2)
}
- Automatic derivation type : The so-called automatic derivation type , Just don't go through var Declare variables , Don't specify type , Directly follow the variable name with ”:” Number , Complete the assignment at the same time . that GO The type of variable will be automatically deduced according to the assigned value . If num The variable is assigned a decimal number , Then the type of the variable is decimal ( floating-point )
func main() {
num := 10
num1 := 20
a, b, c :=12, 13, 14
fmt.Println(num, num1)
fmt.Println(a, b, c)
}
- Case study : In exchange for 2 Values of variables ( Realization 2)
func main() {
num1 := 10
num2 := 20
num1, num2 = num2,num1
fmt.Println(num1,num2)
}
Two 、 Input and output format control
- Println: Formatted output
- Printf: Format output ,
%d
Indicates that the output is the value in an integer variable ,\n
Means line break
func main() {
num1 := 10
num2 := 20
num3 := 30
fmt.Println(num1, num2, num3)
fmt.Println("num1=", num1)
fmt.Printf("num1 = %d\n", num1)
fmt.Printf("num2 = %d,num3 = %d",num2, num3)
}
- Scanf:Scanf() Grammar format :fmt.Scanf(“%d”,&num)
- Scan:Scan() Grammar format : fmt.Scan(&num)
- Variable address : In memory, corresponding storage units will be opened up for variables , In order to be able to find the storage unit, access data , The system will add a number to each unit , This number is the address
- Scan and Scanf The difference between :Scan You do not need to specify a formatter , later stage Scan More frequently used
package main
import "fmt"
func main() {
var age int
fmt.Println(" Please enter age :")
/* fmt.Scanf("%d",&age) // adopt Scanf The function assigns the data entered by the keyboard to the variable , But variables must be preceded by & fmt.Println("age = ",age) fmt.Println(&age) fmt.Printf("%p",&age) */
fmt.Scan(&age)
fmt.Println("age = ", age)
}
3、 ... and 、 Computer base system
A simple understanding of , And there are a lot of information on the Internet , Including binary conversion and so on
- What is base : The method of counting according to the principle of carry is called carry counting system .“ Carry numeration system ” Referred to as “ Number system ” or “ Base number ”
- The carry of each number system follows a rule , That's it ---- Meet N Into the 1
- Hexadecimal features
- Use a fixed set of numbers to represent the size of the value . Such as : The decimal number is 0,1,2,3,4,5,6,7,8,9
- Uniform rules : Meet N Jin Yi
- Binary element
- base : there N It's called cardinality . So-called “ base ” It refers to the number of basic digits allowed in various binary counting systems
- Position right :215=2*102 + 1*101 + 5*100 , among 102 , 101 ,100 Position right
- Add by weight : Multiply the numeric character on each bit by the weight it represents
Four 、 Variable naming conventions
- Naming specification
- ①. Only numbers , Letter ,_( Underline ) form
- ②. Cannot start with a number
- ③. Capital letters and lowercase letters are different :heapSort and Heapsort It's two different names
- ④. It can't be a keyword
- Naming rules
- Hump nomenclature
- Little hump nomenclature (lower camel case): The first word begins with a lowercase letter ; The first letter of the second word is capitalized , for example : myName、aDog
- Big hump nomenclature (upper camel case): The first letter of each word is capital , for example :FirstName、 LastName
- Underline separation : Multiple word names , Write in all lowercase letters , In the middle _ Separate , for example :first_name、user_name
- Hump nomenclature
版权声明
本文为[Endless character]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231437070977.html
边栏推荐
- The art of automation
- 三、梯度下降求解最小θ
- [jz46 translate numbers into strings]
- Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
- SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
- 8.5 循环神经网络简洁实现
- C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】
- qt之.pro文件详解
- 查找水仙花数-for循环实践
- The initial C language framework is suitable for review and preliminary understanding
猜你喜欢
ASEMI三相整流桥和单相整流桥的详细对比
如何5分钟上手使用OCR
【Servlet】Servlet 详解(使用+原理)
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
we引用My97DatePicker 实现时间插件使用
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
顺序表的操作,你真的学会了吗?
GIS数据处理-cesium中模型位置设置
PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
随机推荐
解决computed属性与input的blur事件冲突问题
详解TCP的三次握手
线程同步、生命周期
Detailed explanation of C language P2 selection branch statement
pnpm安装使用
Basic regular expression
Nacos uses demo as configuration center (IV)
初识STL
一个月把字节,腾讯,阿里都面了,写点面经总结……
分分钟掌握---三目运算符(三元运算符)
拼接hql时,新增字段没有出现在构造方法中
循环队列的基本操作,你学会了吗?
【工厂模式详解】工厂方法模式
8.5 循环神经网络简洁实现
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
一篇博客让你学会在vscode上编写markdown
Some little records~
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
ASEMI超快恢复二极管与肖特基二极管可以互换吗
剑指 Offer II 019. 最多删除一个字符得到回文(简单)