当前位置:网站首页>[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
边栏推荐
- 1293_FreeRTOS中xTaskResumeAll()接口的实现分析
- 动态库基本原理和使用方法,-fPIC 选项的来龙去脉
- Common selectors are
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
- Lecture 1: the entry node of the link in the linked list
- How to measure whether the product is "just needed, high frequency, pain points"
- 从服务器到云托管,到底经历了什么?
- [OBS] the official configuration is use_ GPU_ Priority effect is true
- When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
猜你喜欢
C# 泛型及性能比较
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
Kubernetes Static Pod (静态Pod)
Cause analysis and solution of too laggy page of [test interview questions]
STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
52歲的周鴻禕,還年輕嗎?
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
华为交换机S5735S-L24T4S-QA2无法telnet远程访问
Detailed explanation of interview questions: the history of blood and tears in implementing distributed locks with redis
How to learn a new technology (programming language)
随机推荐
Lecture 1: the entry node of the link in the linked list
When creating body middleware, express Is there any difference between setting extended to true and false in urlencoded?
51与蓝牙模块通讯,51驱动蓝牙APP点灯
什么是负载均衡?DNS如何实现负载均衡?
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
[programming problem] [scratch Level 2] draw ten squares in December 2019
Installation and configuration of sublime Text3
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
Open display PDF file in web page
ABAP ALV LVC template
Smart regulation enters the market, where will meituan and other Internet service platforms go
快速上手使用本地测试工具postman
Introduction to paddle - using lenet to realize image classification method I in MNIST
RPA cloud computer, let RPA out of the box with unlimited computing power?
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
DNS 系列(一):为什么更新了 DNS 记录不生效?
丸子官网小程序配置教程来了(附详细步骤)