码迷,mamicode.com
首页 > 其他好文 > 详细

Go 打印对比

时间:2019-10-15 18:57:57      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:博客   nbsp   int   for   form   font   type   对比   一句话   

Go中打印有两种方式

  1.Printf

  2. Println

  最烦的这两种都是打印,但是有的时候你打印的时候结果不是你想要的,甚至还会报错,现在强哥拿出单独的一篇博客来说明这个问题,由此可见这个问题我也怕自己忘记了,哈哈,废话不多说还是,直接上代码

Printf 和 Println的去区别

package main
import "fmt"
const s, ss = 1, 2
func main() {
    fmt.Println(s, ss) //单纯的打印
    fmt.Printf("s is of type %T\n", s) // s is of type int
    fmt.Println("s is of type %T\n", s) // s is of type %T 
                                                          1  --> 这里是\n
}    

总结其实就是一句话:

    Printf可以格式化输出字符串,但是Println则不会,

    对比Python,Printf类似python中的.format

Go 打印对比

标签:博客   nbsp   int   for   form   font   type   对比   一句话   

原文地址:https://www.cnblogs.com/lzqrkn/p/11679290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!