golang

164 阅读1分钟

官网

  • golang.google.cn/
  • Go 是一个开源的编程语言,它能让构造简单、可靠且高效的软件变得容易。

学习方法

  1. 高效而愉快的学习,要学就认真的学,不要三天打鱼两天晒网。
  2. 先建立整体框架,再细节。
  3. 实际工作中,要培养自己的学习能力,善于查阅资料。
  4. 先know how, 再know why【工科】。

如何学习

  • 与其他语言进行对比学习
  • 多多练习【重点】
  • 在工作中使用go语言
  • 培养自主学习能力

hello world

package main

// 导入语句
import (
	"fmt"
)

// 函数外只能放置标识符(变量、常量、函数、类型)的声明
// fmt.Println("hello world") //非法

// 程序入口函数
func main()  {
	fmt.Println("hello world")
}
关键字
  • Go 代码中会使用到的 25 个关键字或保留字:
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
  • 还有 37 个预定义标识符
    Constants:    true  false  iota  nil

        Types:    int  int8  int16  int32  int64  
                  uint  uint8  uint16  uint32  uint64  uintptr
                  float32  float64  complex128  complex64
                  bool  byte  rune  string  error

    Functions:   make  len  cap  new  append  copy  close  delete
                 complex  real  imag
                 panic  recover