Golang中println和fmt.Println区别是什么

发布时间:2023-03-21 13:54:35 作者:iii
来源:亿速云 阅读:84

本篇内容主要讲解“Golang中println和fmt.Println区别是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Golang中println和fmt.Println区别是什么”吧!

println()

先看下 println() 方法的注释:

// The println built-in function formats its arguments in an
// implementation-specific way and writes the result to standard error.
// Spaces are always added between arguments and a newline is appended.
// Println is useful for bootstrapping and debugging; it is not guaranteed
// to stay in the language.

可以看出 println() 是内置方法,属于builtin 包(builtin包是Golang预声明的包,不需要 import 即可使用),可以传入多个Type类型(pointer、channel、func、 interface、map和slice 类型)参数,将结果写入标准错误。主要用于调试,不保证在未来的 Golang 版本中还保留此方法。

fmt.println()

再看下 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

可以看出 fmt.println() 属于 fmt 包,可以传入多个 interface 类型的参数,将结果写入标准输出。返回两个参数——写入的字节数和error。

println() 和 fmt.println() 的区别

通过上面的注释和说明可以看出如下区别:

到此,相信大家对“Golang中println和fmt.Println区别是什么”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. shell脚本可以被golang编写吗
  2. golang快速入门[6.2]-集成开发环境-emacs详解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

golang println

上一篇:python人工智能算法之决策树流程是什么

下一篇:python人工智能算法之人工神经网络怎么使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》