Values and Variables

Values

package main

import "fmt"

func main() {
    fmt.Println("go" + "lang") //λ¬Έμžμ—΄μ€ +둜 더할 수 있
    
    fmt.Println("1+1 =", 1+1)
    fmt.Println("7.0/3.0 =", 7.0/3.0)
    
    fmt.Println(true && false) //λΆˆλ¦¬μ–Έλ„ λ‹Ήμ—°νžˆ κ°€λŠ₯ν•˜
    fmt.Println(true || false)
    fmt.Println(!true)
}
  • Go has various value types. Here are a few basic examples.

Variables

package main

import "fmt"

func main() {
    
    var a = "initial"
    
    var b, c int = 1, 2

    var d = true
    
    var e int // is 0
    fmt.Println(e)
    
    var g string // is ""
    
    fmt.Println(g == "") // true
    
    f := "apple" // μ„ μ–Έκ³Ό μ΄ˆκΈ°ν™”λ₯Ό λ™μ‹œ
    fmt.Println(f)
}
  • var declares 1 or more variables.

  • You can declare multiple variables at once - var b, c int 1, 2

  • Variables declared without initialization are zero-valued.

    • int is 0, string is ""

  • The := syntax is shorthand for declaring and initializing a variable

Last updated