当前位置:网站首页>[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?
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
- QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
- 快速上手使用本地测试工具postman
- Single machine high concurrency model design
- ABAP ALV LVC模板
- 备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
- 爬虫实战(八):爬表情包
- Two small problems in creating user registration interface
猜你喜欢

单机高并发模型设计

Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现

Operating system principle --- summary of interview knowledge points

去了字节跳动,才知道年薪 40w 的测试工程师有这么多?

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

【测试面试题】页面很卡的原因分析及解决方案

"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points

Service Mesh介绍,Istio概述

深潜Kotlin协程(二十二):Flow的处理

取消select的默认样式的向下箭头和设置select默认字样
随机推荐
How to insert highlighted code blocks in WPS and word
ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务
CoinDesk评波场去中心化进程:让人们看到互联网的未来
Reading notes 004: Wang Yangming's quotations
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
Flask learning record 000: error summary
Service Mesh的基本模式
从服务器到云托管,到底经历了什么?
他们齐聚 2022 ECUG Con,只为「中国技术力量」
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
What has happened from server to cloud hosting?
Installation and configuration of sublime Text3
Single machine high concurrency model design
The difference between -s and -d when downloading packages using NPM
redis你到底懂不懂之list
How to learn a new technology (programming language)
商品的设计等整个生命周期,都可以将其纳入到产业互联网的范畴内
Usage of limit and offset (Reprint)
【转载】解决conda安装pytorch过慢的问题