Files
go_test/2.输出.go

29 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import "fmt"
func main () {
print()
}
func print() {
fmt.Printf("123\n") // 一般输出加换行 (我自认为)
fmt.Println("自带换行") // 自带换行输出 (好用)
fmt.Println("你好","世界","你好哦") // 输出可以,输出多个不同的输出
// 格式化输出
fmt.Printf("%s 喜欢rap篮球\n", "蔡徐坤") // 字符串输出 后面等于 %s ,不能多个%s叠加
fmt.Printf("%d\n",32) // 整数输出 不能打双引号
fmt.Printf("%f\n",3.1415926) // 小数输出 默认保留6位
fmt.Printf("%.3f\n",3.1415926) // 小数输出 %.3f保留3位
fmt.Printf("%T %T \n", "法人",32.33) // 打印文本类型的输出
fmt.Printf("%T %T %T %T %T\n", "法人",32.33,333,"fwafafgag","&&&&&") // 打印文本类型的输出
fmt.Printf("%v %v %v %v\n","fwaf",325,33.5,"你好") // 输出任意
fmt.Printf("%v\n","fwaf",325,33.5,"你好") // 但是一个 %后面的参数 只能打印一个
fmt.Printf("\n%#v\n","不知道") // 不知道怎么形容,总之就是输出的时候包括引号
// 将变量赋予格式化输出
var pai = fmt.Sprintf("%f",3.14) // 注意是Sprintf哦
fmt.Println(pai) //这也会触发小数输出 默认保留6位
}