갈루아의 반서재

불린값은 true 또는 false 를 나타내는 1비트 정수 타입으로, 아래 3가지 연산자가 불린값을 가진다. 

&&and
||or
!not

아래의 예를 통해 불린값의 사용법을 알아보자. 

1
2
3
4
5
6
7
8
9
10
11
package main
 
import "fmt"
 
func main() {
  fmt.Println(true && true)
  fmt.Println(true && false)
  fmt.Println(true || true)
  fmt.Println(true || false)
  fmt.Println(!true)
}
cs

실행하면 다음과 같다. 

1
2
3
4
5
6
~/go/src/golang-book/chapter3# go run main.go
true
false
true
true
false
cs

다음과 같은 진리표를 보통 사용한다. 

ExpressionValue
true && truetrue
true && falsefalse
false && truefalse
false && falsefalse
ExpressionValue
true || truetrue
true || falsetrue
false || truetrue
false || falsefalse
ExpressionValue
!truefalse
!falsetrue