go中Println和Printf的区别
Don’t worry , just coding!
内耗与overthinking只会削弱你的精力,虚度你的光阴,每天迈出一小步,回头时发现已经走了很远。
go中Println和Printf的区别
package main
import (
"fmt"
)
//TIP To run your code, right-click the code and select <b>Run</b>. Alternatively, click
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.
func main() {
//TIP Press <shortcut actionId="ShowIntentionActions"/> when your caret is at the underlined or highlighted text
// to see how GoLand suggests fixing it.
s := "gopher"
fmt.Println("Hello and welcome, %s!", s)
fmt.Printf("Hello and welcome, %s!\n", s)
for i := 1; i <= 5; i++ {
//TIP You can try debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>. To start your debugging session,
// right-click your code in the editor and select the <b>Debug</b> option.
fmt.Println("i =", 100/i)
}
}
//TIP See GoLand help at <a href="https://www.jetbrains.com/help/go/">jetbrains.com/help/go/</a>.
// Also, you can try interactive lessons for GoLand by selecting 'Help | Learn IDE Features' from the main menu.
输出:
区别:Println会显示%s这个占位字符本身,Printf不会显示
掌握知识的最好方式就是教会别人,每篇文章都讲清楚一个知识点,欢迎留言我一起讨论。