Go语言入门教程.docx

  1. 1、本文档共44页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Go语言入门教程

/viewtopic.php?f=4t=35Go语言入门教程Introduction 简介This document is a tutorial introduction to the basics of the Go programming language, intended for programmers familiar with C or C++. It is not a comprehensive guide to the language; at the moment the document closest to that is the language specification. After youve read this tutorial, you might want to look at Effective Go, which digs deeper into how the language is used. Also, slides from a 3-day course about Go are available: Day 1, Day 2, Day 3.本文是关于Go编程语言的基础教程,主要面向有C/C++基础的读者。本文并不是一个语言的完整指南,关于 Go的具体细节请参考 语言规范 一文。在学习完入门教程后,还可以继续看 Effective Go ,这个文档将涉及到Go语言的更多特性。此外,还有一个《Go语言三日教程》系列讲座: 第一日, 第二日, 第三日。The presentation here proceeds through a series of modest programs to illustrate key features of the language. All the programs work (at time of writing) and are checked into the repository in the directory /doc/progs/.下面将通过一些小程序来掩饰语言的一些关键特性。所有的演示程序都是可以运行的,程序的代码在安装目录的 /doc/progs/子目录中。Program snippets are annotated with the line number in the original file; for cleanliness, blank lines remain blank.文中的代码篇都都会以代码在源文件中的行号标注。为了清晰起见,我们忽略了源代码文件空白行的行号。Hello, WorldLets start in the usual way:让我们从经典的Hello, World程序开始:代码:?/viewtopic.php?f=4t=35全选05 package main07 import fmt fmt // Package implementing formatted I/O.09 func main() {?10? ? ?fmt.Printf(Hello, world; or Καλημ?ρα κ?σμε; or こんにちは 世界\n)11 }Every Go source file declares, using a package statement, which package its part of. It may also import other packages to use their facilities. This program imports the package fmt to gain access to our old, now capitalized and package-qualified, friend, fmt.Printf.每个Go源文件开头都有一个package声明语句,指明文件所在的包。同时,我们也可以根据具体的需要来导入(import语句)特定的包文件。在这个例子中,我们通过导入“fmt”包来使用我们熟悉的printf函数。不过在Go语言中,Printf函数的开头是大写字母,并且需要fmt包名作为前缀:fmt.Printf。Functions are introduced with the func keyword. The main packages main function is where the program starts running (after any initialization).函数定义要使用“func“关键字。整个程序从main包中的main函数开始执行(在变量和包初始化之后)。String constants can contain

文档评论(0)

zhuwenmeijiale + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:7065136142000003

1亿VIP精品文档

相关文档