Day 2 of Learning Go: Variables, Types, and CLI Input
Today’s knowelege is quite simple:
Key Concepts
variable
-
Use
varto declare a variable -
use
var a int = 30to declear a as a integer type, or just use
:=like:a := 100to let Go infer the type automatically
Data Type
basic data types:
-
int
-
float64
-
string
-
bool
Cli Input
-
use
fmt.Scan()to get user input -
the parameter should be a pointer, so use
&in front of the varibale
Print Formatting
use fmt.Printf() to format output, common format verbs:
-
%s -> string
-
%d -> integer
-
%f -> float
-
%v -> any type(generic)