当前位置:网站首页>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 .
边栏推荐
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- 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
- 记录线上bug解决list(未完待续7/4)
- Browser render page pass
- 太方便了,钉钉上就可完成代码发布审批啦!
- So this is the BGP agreement
- What ppt writing skills does the classic "pyramid principle" teach us?
- What should I do if my computer sharing printer refuses access
- Idea configuration standard notes
- Fleet tutorial 08 introduction to AppBar toolbar Basics (tutorial includes source code)
猜你喜欢
QT writing the Internet of things management platform 38- multiple database support
Automatic generation of interface automatic test cases by actual operation
NetCore3.1 Json web token 中间件
Form组件常用校验规则-1(持续更新中~)
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
Common verification rules of form components -1 (continuously updating ~)
idea恢复默认快捷键
Fleet tutorial 08 introduction to AppBar toolbar Basics (tutorial includes source code)
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
随机推荐
实操自动生成接口自动化测试用例
Taishan Office Technology Lecture: about the order of background (shading and highlighting)
阿里测试师用UI自动化测试实现元素定位
浏览器渲染页面过程
Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world
实践示例理解js强缓存协商缓存
go语言笔记(2)go一些简单运用
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
关于联邦学习和激励的相关概念(1)
Length of the longest integrable subarray
Integretee integrates into Moonriver through xcm, bringing enterprise class privacy solutions to its ecosystem
Function analysis and source code of hash guessing game system development
Stack: how to realize the judgment of valid brackets?
SSRS筛选器的IN运算(即包含于)用法
托管式服务网络:云原生时代的应用体系架构进化
Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
漫谈客户端存储技术之Cookie篇
Alibaba testers use UI automated testing to achieve element positioning
How to solve the problem that win11 cannot write the value to the registry key?