go 语言 print、printf、println的区别

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
print和println
这两个打印方式类似,只在格式上有区别
 
println 打印的每一项之间都会有空行,print没有,例如:
 
fmt.println("go","python","php",javascript")  // go  python  php  javascript
 
fmt.print("go","python","php",javascript")  // gopythonphpjavascript
 
  
 
 Println 会自动换行,Print 不会,例如
fmt.Println("hello")
fmt.Println("world")
 
// hello
// world
 
 
 
fmt.Print("hello")
fmt.Print("world")
 
// helloworld
 
 
println和printf
printf是格式化输出,在很多场景下比println更方便,举个例子:
func main(){
a:=10
b:=20
c:=30
fmt.println("a=",a,",b=",b,",c=",c)
fmt.printf("a=%d,b=%d,c=%d",a,b,c)
}
%d是站位符,表示数字的十进制表示。printf中的占位符与后面的数字变量--对应。

  1、print()函数,可输出到控制台(不接受任何格式化),语法“fmt.print(str)”;2、println()函数,可输出到控制台并换行,语法“fmt.println(tmp)”;3、printf()函数,只可以打印出格式化的字符串;4、sprintf()函数,可格式化并返回一个字符串;5、fprintf()函数,可格式化并输出到“io.writers”。

查阅

https://www.php.cn/faq/499756.html

 

posted @   飞雪飘鸿  阅读(60)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL
点击右上角即可分享
微信分享提示