当前位置:网站首页>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 .
边栏推荐
- Jekins initialization password not found or not found
- 15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
- FS8B711S14电动红酒开瓶器单片机IC方案开发专用集成IC
- 字节测试工程师十年经验直击UI 自动化测试痛点
- 科普达人丨一文看懂阿里云的秘密武器“神龙架构”
- What is the development of block hash quiz game system? Hash quiz game system development (case mature)
- Qt五子棋人机对战画棋子之QPainter的使用误区总结
- Flet tutorial 05 outlinedbutton basic introduction (tutorial includes source code)
- Alibaba testers use UI automated testing to achieve element positioning
- Idea restore default shortcut key
猜你喜欢
随机推荐
Idea configuration standard notes
Practical examples of node strong cache and negotiation cache
Four traversal methods of binary tree, as well as the creation of binary tree from middle order to post order, pre order to middle order, pre order to post order, and sequence [specially created for t
[in-depth learning] review pytoch's 19 loss functions
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
九齐NY8B062D MCU规格书/datasheet
Cdga | six principles that data governance has to adhere to
更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
Flet tutorial 05 outlinedbutton basic introduction (tutorial includes source code)
九齐单片机NY8B062D单按键控制4种LED状态
word中插入圖片後,圖片上方有一空行,且删除後布局變亂
Flet教程之 04 FilledTonalButton基础入门(教程含源码)
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening
Automatic generation of interface automatic test cases by actual operation
Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
LeetCode 871. Minimum refueling times
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
Is it necessary to apply for code signing certificate for software client digital signature?
实操自动生成接口自动化测试用例
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient









