Article Directory
Arithmetic Operator
Carry out the calculation of numerical variables, the following
sample program
func test5(){
//
var i int = 1
i = i+2
fmt.Println(i) //3
//var i2 = i++ // 报错 unexpected ++ at end of statement
i++
fmt.Println(i) //4
//++i// 报错 syntax error: unexpected ++
//fmt.Println(i) //3
}
important point
- In the division operation, only the integer part is kept and the decimal part is discarded during the integer operation.
- Increment and decrement can only be used independently, cannot be used with assignment and other operators, and operators can only appear after the variable (not before the variable)
Assignment operator
Assign a value to the specified variable The
order of operations is from right to left, the left can only be a variable, and the right can be a variable, expression, constant value
Comparison/relational operators
Used to compare variables, the calculation result can only be true or false, as follows:
sample code
fmt.Println(1>=2) //false
Logical Operators
The final result for the plurality of operation variables bool can only be true or false
Precautions
- && short-circuit and if the first condition is false, the second condition is not judged and returns false directly
- || Short circuit or if the first condition is true, the second condition returns true without judgment