当前位置:网站首页>[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
边栏推荐
- How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
- Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis
- Common selectors are
- 韦东山第三期课程内容概要
- 什么是负载均衡?DNS如何实现负载均衡?
- The difference between get and post
- Is it safe to open an account on the official website of Huatai Securities?
- Stm32f1 and stm32cubeide programming example - rotary encoder drive
- STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
猜你喜欢
深潜Kotlin协程(二十二):Flow的处理
某马旅游网站开发(登录注册退出功能的实现)
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
What has happened from server to cloud hosting?
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
Is Zhou Hongyi, 52, still young?
接口测试要测试什么?
How to insert highlighted code blocks in WPS and word
How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
Trust orbtk development issues 2022
随机推荐
ABAP ALV LVC模板
51与蓝牙模块通讯,51驱动蓝牙APP点灯
【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
The method of server defense against DDoS, Hangzhou advanced anti DDoS IP section 103.219.39 x
某马旅游网站开发(登录注册退出功能的实现)
【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的
22年秋招心得
The difference between -s and -d when downloading packages using NPM
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
“一个优秀程序员可抵五个普通程序员”,差距就在这7个关键点
Which securities company has a low, safe and reliable account opening commission
玩轉Sonar
Su embedded training - Day3
Trust orbtk development issues 2022
商品的设计等整个生命周期,都可以将其纳入到产业互联网的范畴内
Su embedded training - day4
深潜Kotlin协程(二十三 完结篇):SharedFlow 和 StateFlow
Jouer sonar
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動