Integer
package main
import "fmt"
func main() {
fmt.Println("1 + 1 =", 1 + 1)
}
If you run the program and you should see this:
$ go run main.go
1 + 1 = 2
In addition to addition Go has several other operators:
Strings
package main
import "fmt"
func main() {
fmt.Println(len("Hello World"))
fmt.Println("Hello World"[1])
fmt.Println("Hello " + "World")
}
Running this program should give you:
$ go run main.go
10
e
Hello World
Booleans
Here is an example program showing how they can be used:
func main() {
fmt.Println(true && true)
fmt.Println(true && false)
fmt.Println(true || true)
fmt.Println(true || false)
fmt.Println(!true)
}
Running this program should give you:
$ go run main.go
true
false
true
true
false
We usually use truth tables to define how these operators work:
0 yorum:
Yorum Gönder