Values {.en}

值 {.zh}

::: {.en} Go has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples. :::

::: {.zh}

Go 有各种值类型,包括字符串,整数,浮点数,布尔值等。这里有一些基本的例子。

:::

  1. package main
  2. import "fmt"
  3. func main() {

::: {.en} Strings, which can be added together with +. :::

::: {.zh}

字符串可以用+连接。

:::

  1. fmt.Println("go" + "lang")

::: {.en} Integers and floats. :::

::: {.zh}

整数和浮点数。

:::

  1. fmt.Println("1+1 =", 1+1)
  2. fmt.Println("7.0/3.0 =", 7.0/3.0)

::: {.en} Booleans, with boolean operators as you’d expect. :::

::: {.zh}

布尔值,使用布尔运算符。

:::

  1. fmt.Println(true && false)
  2. fmt.Println(true || false)
  3. fmt.Println(!true)
  4. }
  1. $ go run values.go
  2. golang
  3. 1+1 = 2
  4. 7.0/3.0 = 2.3333333333333335
  5. false
  6. true
  7. false