Operators and Built-in Functions
Go supports the normal set of numerical operators. See for lists the current ones and their relative precedence. They all associate fromleft to right.
Precedence | Operator(s) |
---|---|
Highest | * / % << >> & &^ |
`+ - | |
== != < <= > >= | |
<- | |
&& | |
Lowest | || |
Operator precedence.
+ - * /
and %
all do what you would expect, & | ^
and &^
are bitoperators for bitwise and bitwiseor bitwise xor andbit clear respectively. The &&
and ||
operators are logical and and logical or Not listed in the table is the logical not !
Although Go does not support operator overloading (or method overloading forthat matter), some of the built-in operators are overloaded. For instance, +
can be used for integers, floats, complex numbers and strings (adding strings isconcatenating them).
当前内容版权归 Miek Gieben 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Miek Gieben .