golang fmt.Println() 换行输出

fmt.Println()语法

func fmt.Println(a ...any) (n int, err error)

golang源码对fmt.Println()方法的介绍

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

即,golang的fmt标准库中的Println采用默认格式将其参数格式化并写入标准输出,相邻的参数格式化输出后默认在二者之间添加空格,输出结束后会在末尾添加换行符。

fmt.Println()参数

参数描述
afmt.Println()的可变的参数,参数与参数之间使用英文逗号隔开;

fmt.Println()方法返回值

输出的字节数n和可能遇到的error。

fmt.Println()方法实例代码

package main

import (
	"fmt"
)

func main() {
	food_name := "apple"
	food_category := "fruit"
	fmt.Println(food_name, food_category)

}

运行go文件,得到输出:

apple fruit

免责声明:内容仅供参考。


全栈后端 / go语法 :













Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.