当前位置:网站首页>[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
边栏推荐
- C # generics and performance comparison
- 51与蓝牙模块通讯,51驱动蓝牙APP点灯
- 什么是负载均衡?DNS如何实现负载均衡?
- STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
- Trust orbtk development issues 2022
- Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
- Installation and configuration of sublime Text3
- QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
- What has happened from server to cloud hosting?
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
猜你喜欢
Two small problems in creating user registration interface
What has happened from server to cloud hosting?
取消select的默认样式的向下箭头和设置select默认字样
[programming problem] [scratch Level 2] December 2019 flying birds
浪潮云溪分布式数据库 Tracing(二)—— 源码解析
单机高并发模型设计
The underlying principles and templates of new and delete
[the most detailed in history] statistical description of overdue days in credit
How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
What if the testing process is not perfect and the development is not active?
随机推荐
服务器防御DDOS的方法,杭州高防IP段103.219.39.x
How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
They gathered at the 2022 ecug con just for "China's technological power"
3年经验,面试测试岗20K都拿不到了吗?这么坑?
韦东山第三期课程内容概要
Qt不同类之间建立信号槽,并传递参数
Vscode software
Binder核心API
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务
22年秋招心得
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
paddle入门-使用LeNet在MNIST实现图像分类方法二
华为交换机S5735S-L24T4S-QA2无法telnet远程访问
单机高并发模型设计
[programming questions] [scratch Level 2] March 2019 garbage classification
1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
The difference between -s and -d when downloading packages using NPM
Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis
If an exception is thrown in the constructor, the best way is to prevent memory leakage?
Su embedded training - day4