Golang 第一个程序

环境:Sublime3  语言:Go

总起:

Sublime中安装完Package Control功能后,安装Go的开发环境,按下Ctrl + B,输入go run hello.go就能简单的调试Golang程序。

Java和Ruby都在是1995年的时候发布的,现在榜上有名的语言大部分都是上个世纪的产物,而Golang是直到2009年由Google公司发布。

今天对Golang的一些基础进行了学习,除了申明变量和定义类型时的语法有点诡异以外,其他的写起来都很舒服,简单易学可以经过几个例子略窥一二。

代码:

这边记录一下Golang的基本使用和结构:

// 当前程序包名
package main

// 导入其他包
import (
	. "fmt" // .为省略调用
	"strconv"
)

// 常量
const (
	PI = 3.1415926
	R  = 10
)

// 全局变量
var (
	golbalName = "gopher"
	golbalSex  = "male"
)

// 一般类型的申明
type (
	booltype    bool
	inttype     int
	bytetype    byte
	stringtype  string
	float       float32
	double      float64
	ptrtype     uintptr   // 指针
	complextype complex64 // 复数
)

// 结构类型
type Person struct {
}

// 申明接口
type IPerson interface {
}

// 程序入口
func main() {
	var str1 string = "你好"
	var str2 = "Hello"
	str1, str2 = str2, str1

	// 大写的为public
	// 小写的为private
	Println(str1)
	Println(str2)
}


猜你喜欢

转载自blog.csdn.net/u012632851/article/details/78953182
今日推荐