当前位置:网站首页>Go notes (3) usage of go language FMT package
Go notes (3) usage of go language FMT package
2022-07-04 20:47:00 【fiveym】
Introduce
fmt Is a common library for input and output
stay fmt package , There are two kinds of methods for formatting input and output :scan and print
Respectively in scan.go and print.go In file
print: Output function
print Series is mainly used for output , It mainly includes three methods :
print: Output content directly , Don't wrap , Cannot format output .
printf: Format the text output as specified .
println: Can be behind the output Add line breaks .
package main
import "fmt"
func main() {
// When entering multiple values at once Println There's a space in the middle , Can wrap lines automatically
fmt.Println("Hello", "Println")
// When entering multiple values at once Print No middle space ,Print No line wrapping ;
fmt.Print("Hello", "Print")
// Printf Is to format the output , In many scenarios Println More convenient ,Printf I won't change lines
fmt.Printf("Hello Printf %s", "AAA")
}
// Hello Println
// HelloPrintHello Printf AA
print.go It's defined in the file 9 A function
this 9 A function , According to two dimensions, functions can be divided according to two dimensions
// If you put Print Understood as core keywords , Then the suffix followed by " f " and " ln " as well as "", Focus on the final result of the output content ; If the suffix is " f ", Specify the format If the suffix is " ln ", There is a newline character .
Println、Fprintln、Sprintln Line breaks will be added when outputting content ;
Print、Fprint、Sprint Output content without line breaks ;
Printf、Fprintf、Sprintf Format the text output as specified .
// If you put Print Understood as core keywords , Then the prefix in front has " F " and " S " as well as "", Focus on the goal of output content ( terminal ); If the prefix is " F ", Specify the io.Writer If the prefix is " S ", Is output to string
Print、Printf、Println Output content to standard output os.Stdout;
Fprint、Fprintf、Fprintln Output content to the specified io.Writer;
Sprint、Sprintf、Sprintln Output content to string
scan: Output function
scan Series is mainly used to input
Example: get user input in the interactive interface
package main
import "fmt"
func main() {
var name string
fmt.Print(" Enter your name :")
fmt.Scan(&name)
fmt.Printf(" The name you entered is :%s", name)
}
// Enter your name : Wang Jingze
// The name you entered is : Wang Jingze
// It is worth noting that ,Scan You need to use &, Otherwise, it will be regarded as direct transmission .
scan.go It's defined in the file 9 A function :
this 9 Functions can scan formatted text to generate values . It can also be explained according to two dimensions .
/* If you put " Scan " Understood as core keywords , Then the suffix followed by " f " and " ln " as well as "", Focus on the results of the input ; If the suffix is " f ", Specify the format If the suffix is " ln ", There is a newline character */
Scanln、Fscanln、Sscanln Stop when reading line breaks , And ask for one line of all entries at a time ;
Scan、Fscan、Sscan Don't pay attention to line breaks when reading content ;
Scanf、Fscanf、Sscanf Read from formatted text .
/* If you put " Scan " Understood as core keywords , Then the prefix in front has " F " and " S " as well as "", Focus on the source of input content ( terminal ); If the prefix is " F ", Specify the io.Reader If the prefix is " S ", Is read from the string */
Scan、Scanf、Scanln From standard input os.Stdin Read text ;
Fscan、Fscanf、Fscanln From the specified io.Reader Interface reads text ;
Sscan、Sscanf、Sscanln Read text from a parameter string .
边栏推荐
- How to adapt your games to different sizes of mobile screen
- 最长的可整合子数组的长度
- How does win11 search for wireless displays? Win11 method of finding wireless display device
- word中插入图片后,图片上方有一空行,且删除后布局变乱
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
- MySQL statement execution details
- PermissionError: [Errno 13] Permission denied: ‘data.csv‘
- 电脑共享打印机拒绝访问要怎么办
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
猜你喜欢
黄金k线图中的三角形有几种?
Qt五子棋人机对战画棋子之QPainter的使用误区总结
Idea configuration standard notes
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
Understand the reading, writing and creation of files in go language
Fleet tutorial 08 introduction to AppBar toolbar Basics (tutorial includes source code)
#夏日挑战赛#带你玩转HarmonyOS多端钢琴演奏
Automatic generation of interface automatic test cases by actual operation
How does win11 search for wireless displays? Win11 method of finding wireless display device
Win11系统wifi总掉线怎么办?Win11系统wifi总掉线的解决方法
随机推荐
太方便了,钉钉上就可完成代码发布审批啦!
Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
面对同样复杂的测试任务为什么大老很快能梳理解决方案,阿里十年测试工程师道出其中的技巧
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
Idea plug-in
Flet教程之 07 PopupMenuButton基础入门(教程含源码)
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
Advantages of semantic tags and block level inline elements
Huawei cloud store homepage banner resource bit application
From automation to digital twins, what can Tupo do?
In operation (i.e. included in) usage of SSRs filter
Fleet tutorial 08 introduction to AppBar toolbar Basics (tutorial includes source code)
Why is the maximum speed the speed of light
QT writing the Internet of things management platform 38- multiple database support
Understand the reading, writing and creation of files in go language
MySQL statement execution details
Flet教程之 05 OutlinedButton基础入门(教程含源码)
针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
How does the computer save web pages to the desktop for use