Variables and Data Types
var and := declarations, the int, int64, float64, string, bool types.
Go has two ways to create a variable:
• the full form: var age int = 15 (the type can be omitted — var age = 15);
• the short form := — works only inside functions: age := 15. In practice you almost always write this one.
The main types:
• int — integers (64-bit on this server, up to 9·10¹⁸);
• int64 — an explicitly 64-bit integer;
• float64 — floating-point numbers;
• string — a string;
• bool — true or false.
Go
Variables and printing their types
fmt.Printf prints by format: %d — an integer, %f — a float, %s — a string, %T — the type of a value, \n — a newline.
Arithmetic: + - * / %. Integer division discards the fractional part: 7 / 2 equals 3, the remainder 7 % 2 equals 1.
Go is strict about types: you cannot add an int and a float64 directly — an explicit conversion is required, e.g. float64(a).
Go
Integer division and type conversion
Task: create variables with the values 15 and 4 and print the sum, difference, product, integer quotient and remainder — each on its own line.
Then mark the lesson as completed.