当前位置:网站首页>[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
2022-07-08 00:33:00 【InfoQ】
One 、 Automatic derivation type
1. Automatic derivation type
package main
import "fmt"
func main() {
// initialization
var a int = 10
// assignment
a = 20
// Automatic derivation
b := 30
// Output
fmt.Println(a, b)
}
2. summary
- What is automatic derivation type : When declaring assignment variables , Unwanted var And variable types , Its type is determined by the assigned value .
- Automatically deduce the basic syntax format of the type :“ Variable name := value ”.
- Multiple assignments ( Use the automatic derivation type to assign values to multiple variables at one time ) Grammar format :“ Variable name 1, Variable name 2, Variable name 3:= value 1, value 2, value 3"
Two 、 Input and output
1. Output
1.1 fmt.Print
func Print(a ...interface{}) (n int, err error)
- Print Format its parameters in the default format and write them to standard output .
- If two adjacent parameters are not strings , A space is added between their outputs .
- Returns the number of bytes written and any errors encountered .
1.2 fmt.Println
func Println(a ...interface{}) (n int, err error)
- Println Format its parameters in the default format and write them to standard output .
- Spaces are always added between adjacent output parameters and the end of the line breaks .
- Returns the number of bytes written and any errors encountered .
1.3 fmt.Printf
func Printf(format string, a ...interface{}) (n int, err error)
- Printf according to format Parameter generates a formatted string and writes it to standard output .
- Returns the number of bytes written and any errors encountered .
2. Input
2.1 fmt.Scan
func Scan(a ...interface{}) (n int, err error)
- Scan Scan text from standard input , Save the successfully read white space delimited value into the file passed to - The parameters of this function . Line breaks are treated as white space .
- Returns the number of items successfully scanned and any errors encountered . If fewer entries are read than the parameters provided , Will return an error report reason .
package main
import "fmt"
func main() {
var (
name string
age int
isMale bool
)
fmt.Scan(&name, &age, &isMale)
fmt.Printf(" Scan results name:%s age:%d isMarried:%t \n", name, age, isMale)
}

2.2 fmt.Scanf
func Scanf(format string, a ...interface{}) (n int, err error)
- Scanf Scan text from standard input , according to format The format specified by the parameter saves the successfully read blank separated value into the parameter successfully passed to this function .
- Returns the number of items successfully scanned and any errors encountered .
package main
import "fmt"
func main(){
var (
name string
age int
isMale bool
)
fmt.Scanf("name:%s age:%d isMale:%v", &name, &age, &isMale)
//fmt.Scanf("%s%d%t",&name,&age,&isMale) It is recommended that , When typing, use a space between
fmt.Printf(" Scan results name:%s age:%d isMarried:%t \n", name, age, isMale)
}

2.3 summary
- Scanf() Grammar format :fmt.Scanf("%d",&num)
- Scan() Grammar format :fmt.Scan(&num)
- Variable address : In memory, corresponding storage units will be opened up for variables , In order to find the storage unit access data , The system will add a number to each unit , This number is the address
边栏推荐
- What is load balancing? How does DNS achieve load balancing?
- 从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
- Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
- 接口测试进阶接口脚本使用—apipost(预/后执行脚本)
- 腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
- NVIDIA Jetson测试安装yolox过程记录
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
- 从服务器到云托管,到底经历了什么?
- How to measure whether the product is "just needed, high frequency, pain points"
- Su embedded training - day4
猜你喜欢

Development of a horse tourism website (realization of login, registration and exit function)

【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的

An error is reported during the process of setting up ADG. Rman-03009 ora-03113

玩轉Sonar

Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现

Langchao Yunxi distributed database tracing (II) -- source code analysis

5G NR 系统消息

Jouer sonar

Binder核心API

52岁的周鸿祎,还年轻吗?
随机推荐
Two small problems in creating user registration interface
什么是负载均衡?DNS如何实现负载均衡?
A brief history of information by James Gleick
Relevant methods of sorting arrays in JS (if you want to understand arrays, it's enough to read this article)
Handwriting a simulated reentrantlock
tourist的NTT模板
浪潮云溪分布式数据库 Tracing(二)—— 源码解析
[the most detailed in history] statistical description of overdue days in credit
Qt不同类之间建立信号槽,并传递参数
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
韦东山第三期课程内容概要
Common selectors are
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
某马旅游网站开发(登录注册退出功能的实现)
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
Development of a horse tourism website (realization of login, registration and exit function)
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?