当前位置:网站首页>[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:30:00 【Hua Weiyun】
One 、 Automatic derivation type
1. Automatic derivation type
Automatic derivation type , When declaring assignment variables , Unwanted var And variable types , Its type is determined by the assigned value .
package mainimport "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
Normal output
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
Line feed output
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
Format output
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
Normal input
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 .
Case study :
package mainimport "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
Format input
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 .
Case study :
package mainimport "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
边栏推荐
- How to learn a new technology (programming language)
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
- Linkedblockingqueue source code analysis - add and delete
- ABAP ALV LVC模板
- Daily question brushing record (16)
- Emotional post station 010: things that contemporary college students should understand
- 玩轉Sonar
- 【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
- new和delete的底层原理以及模板
- Summary of the third course of weidongshan
猜你喜欢

STM32F1与STM32CubeIDE编程实例-旋转编码器驱动

Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet

《因果性Causality》教程,哥本哈根大学Jonas Peters讲授

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

51与蓝牙模块通讯,51驱动蓝牙APP点灯

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

3 years of experience, can't you get 20K for the interview and test post? Such a hole?

某马旅游网站开发(登录注册退出功能的实现)

Binder核心API

Development of a horse tourism website (optimization of servlet)
随机推荐
攻防演练中沙盘推演的4个阶段
[OBS] the official configuration is use_ GPU_ Priority effect is true
What if the testing process is not perfect and the development is not active?
DNS 系列(一):为什么更新了 DNS 记录不生效?
CoinDesk评波场去中心化进程:让人们看到互联网的未来
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
Kubernetes Static Pod (静态Pod)
Summary of the third course of weidongshan
Trust orbtk development issues 2022
测试流程不完善,又遇到不积极的开发怎么办?
Operating system principle --- summary of interview knowledge points
How to measure whether the product is "just needed, high frequency, pain points"
redis你到底懂不懂之list
new和delete的底层原理以及模板
Two small problems in creating user registration interface
SQL knowledge summary 004: Postgres terminal command summary
[the most detailed in history] statistical description of overdue days in credit
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
Open display PDF file in web page
接口测试要测试什么?