当前位置:网站首页>[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
边栏推荐
- 智慧监管入场,美团等互联网服务平台何去何从
- Prompt configure: error: required tool not found: libtool solution when configuring and installing crosstool ng tool
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- 5G NR 系统消息
- ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
- Su embedded training - day4
- Qt不同类之间建立信号槽,并传递参数
- Hotel
- [programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
- C language 005: common examples
猜你喜欢
Lecture 1: the entry node of the link in the linked list
测试流程不完善,又遇到不积极的开发怎么办?
Two small problems in creating user registration interface
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
Langchao Yunxi distributed database tracing (II) -- source code analysis
C# 泛型及性能比较
Service Mesh介绍,Istio概述
DNS series (I): why does the updated DNS record not take effect?
Fully automated processing of monthly card shortage data and output of card shortage personnel information
ReentrantLock 公平锁源码 第0篇
随机推荐
Operating system principle --- summary of interview knowledge points
How to insert highlighted code blocks in WPS and word
动态库基本原理和使用方法,-fPIC 选项的来龙去脉
Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
取消select的默认样式的向下箭头和设置select默认字样
【转载】解决conda安装pytorch过慢的问题
Summary of the third course of weidongshan
They gathered at the 2022 ecug con just for "China's technological power"
攻防演练中沙盘推演的4个阶段
C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks
去了字节跳动,才知道年薪 40w 的测试工程师有这么多?
Two small problems in creating user registration interface
Service Mesh的基本模式
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
RPA云电脑,让RPA开箱即用算力无限?
Reading notes 004: Wang Yangming's quotations
Binder核心API
What has happened from server to cloud hosting?
3年经验,面试测试岗20K都拿不到了吗?这么坑?
玩转Sonar