-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_datatype.go
44 lines (35 loc) · 1.07 KB
/
02_datatype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import "fmt"
func main() {
fmt.Println("Datatypes")
//declare a variable in go
// var variableName datatype
var score int
var cityName string
var check bool
var lifeline float32
score = 88
cityName = "KL"
check = true
lifeline = 88.88
fmt.Println(score)
fmt.Println(cityName)
fmt.Println(check)
fmt.Println("Score: ", score)
fmt.Println("CityName: ", cityName)
fmt.Println("Check: ", check)
fmt.Println("Lifeline: ", lifeline)
fmt.Println("My Score is ", score, ". I live in", cityName)
//use fromat specifier
//add backspace \n to add new line
fmt.Printf("My Score is %v. I live in %v. \n", score, cityName)
fmt.Printf("My lifeline is %v. \n", lifeline)
//%V format specifier - get datatype of variable
fmt.Printf("Datatype of lifeline variable is %V. \n", lifeline)
//auto type inference
//let go detect the datatype of the variable automatically
//use :=
autoScore := "PASS"
fmt.Printf("My autoScore is %v. \n", autoScore)
fmt.Printf("Datatype of autoscore variable is %V. \n", autoScore)
}