当前位置:网站首页>[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
边栏推荐
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- 接口测试要测试什么?
- 【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
- [programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
- Stm32f1 and stm32cubeide programming example - rotary encoder drive
- [the most detailed in history] statistical description of overdue days in credit
- 【笔记】常见组合滤波电路
- Langchao Yunxi distributed database tracing (II) -- source code analysis
- Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
- The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
猜你喜欢
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
智慧监管入场,美团等互联网服务平台何去何从
How to measure whether the product is "just needed, high frequency, pain points"
他们齐聚 2022 ECUG Con,只为「中国技术力量」
玩转Sonar
Development of a horse tourism website (realization of login, registration and exit function)
赞!idea 如何单窗口打开多个项目?
随机推荐
玩转Sonar
How can CSDN indent the first line of a paragraph by 2 characters?
Linkedblockingqueue source code analysis - add and delete
接口测试要测试什么?
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
Summary of weidongshan phase II course content
韦东山第二期课程内容概要
The method of server defense against DDoS, Hangzhou advanced anti DDoS IP section 103.219.39 x
When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
How to add automatic sorting titles in typora software?
Notice on organizing the second round of the Southwest Division (Sichuan) of the 2021-2022 National Youth electronic information intelligent innovation competition
SQL knowledge summary 004: Postgres terminal command summary
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
某马旅游网站开发(登录注册退出功能的实现)
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
paddle入门-使用LeNet在MNIST实现图像分类方法一
5G NR 系统消息
How to learn a new technology (programming language)
CoinDesk评波场去中心化进程:让人们看到互联网的未来
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务