Burdasınız :Ana Sayfa » Programlama » Go Programming - Types

Go Programming - Types

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:
+addition
-subtraction
*multiplication
/division
%remainder

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

&&and
||or
!not
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:
ExpressionValue
true && true= true
true && false= false
false && true= false
false && false= false
ExpressionValue
true || true= true
true || false= true
false || true= true
false || false= false
ExpressionValue
!true= false
!false= true

0 yorum:

Yorum Gönder