Help us understand the problem. What is going on with this article?

Go by Example: Values

More than 5 years have passed since last update.

(この記事は Go by Example: Values を翻訳したものです。)

Goにはstring, integer, float, booleanなどのさまざまな方があるが、ここでは例を少し紹介する。

package main

import "fmt"

func main() {
    // Stringsは+で足すことができる。
    fmt.Println("go" + "lang")

    // intgers と float
    fmt.Println("1+1 =", 1+1)
    fmt.Println("7.0/3.0 =", 7.0/3.0)

    // Booleansとあなたがいつも使っているようなオペレータ
    fmt.Println(true && false)
    fmt.Println(true || false)
    fmt.Println(!true)
}


$ go run values.go
golang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false



int - float

package main

import "fmt"

func main() {
    // int / int
    fmt.Println("1/3 =", 1/3)
    // int / float
    fmt.Println("1/3.0 =", 1/3.0)
}
$ go run int-float.go
1/3 = 0
1/3.0 = 0.3333333333333333

pythonの2系と同じ結果
int / intはfloatにならない。

giwa
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away