当前位置:网站首页>[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 can CSDN indent the first line of a paragraph by 2 characters?
- [C language] objective questions - knowledge points
- Operating system principle --- summary of interview knowledge points
- 51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
- Service Mesh的基本模式
- Usage of limit and offset (Reprint)
- The difference between -s and -d when downloading packages using NPM
- Binder核心API
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- Daily question brushing record (16)
猜你喜欢

玩转Sonar

搭建ADG过程中复制报错 RMAN-03009 ORA-03113

Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布

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

华为交换机S5735S-L24T4S-QA2无法telnet远程访问

Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better

Trust orbtk development issues 2022

C # generics and performance comparison

How to learn a new technology (programming language)

C language 005: common examples
随机推荐
STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
Service Mesh介绍,Istio概述
Is it safe to open an account on the official website of Huatai Securities?
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
3年经验,面试测试岗20K都拿不到了吗?这么坑?
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
redis你到底懂不懂之list
[programming problem] [scratch Level 2] draw ten squares in December 2019
Stm32f1 and stm32cubeide programming example - rotary encoder drive
Linkedblockingqueue source code analysis - add and delete
Lecture 1: the entry node of the link in the linked list
paddle入门-使用LeNet在MNIST实现图像分类方法一
DNS 系列(一):为什么更新了 DNS 记录不生效?
Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
某马旅游网站开发(登录注册退出功能的实现)
Qt不同类之间建立信号槽,并传递参数
[basis of recommendation system] sampling and construction of positive and negative samples
Introduction to paddle - using lenet to realize image classification method I in MNIST
Is Zhou Hongyi, 52, still young?
CoinDesk评波场去中心化进程:让人们看到互联网的未来