# Go之旅（六）

## 原文

tour.golang.org/basics/12

tour.golang.org/basics/13

tour.golang.org/basics/14

tour.golang.org/basics/15

## 译文

### 零值

1. `0`为数值类型零值
2. `false`为布尔类型零值
3. `""`（空字符串）为字符串类型零值
``````package main

import (
"fmt"
"math"
)

func main() {
var x, y int = 3, 4
var f float64 = math.Sqrt(float64(x*x + y*y))
var z uint = uint(f)
fmt.Println(x, y, z)
}

### 类型转换

``````var i int = 42
var f float64 = float64(i)
var u uint = uint(f)

``````i := 42
f := float64(i)
u := uint(f)

### 类型推断

``````var i int
j := i // j is an int

``````i := 42           // int
f := 3.142        // float64
g := 0.867 + 0.5i // complex128

### 常量

``````package main

import "fmt"

const Pi = 3.14

func main() {
const World = "世界"
fmt.Println("Hello", World)
fmt.Println("Happy", Pi, "Day")

const Truth = true
fmt.Println("Go rules?", Truth)
}

### 数值常量

`int`能存储最大值64位的整型，有时略小）

``````package main

import "fmt"

const (
// Create a huge number by shifting a 1 bit left 100 places.
// In other words, the binary number that is 1 followed by 100 zeroes.
Big = 1 << 100
// Shift it right again 99 places, so we end up with 1<<1, or 2.
Small = Big >> 99
)

func needInt(x int) int { return x*10 + 1 }
func needFloat(x float64) float64 {
return x * 0.1
}

func main() {
fmt.Println(needInt(Small))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big))
fmt.Println(needInt(Big))
}