= | 将一个表达式的值赋给一个左值 | c = a + b |
+= | 相加后在赋值 | c += a等于c = c + a |
-= | 相减后在赋值 | c -= a等于c = c - a |
*= | 相乘后在赋值 | c *= a等于c = c * a |
/= | 相除后在赋值 | c /= a等于c = c / a |
%= | 求余后在赋值 | c %= a等于 c = c % a |
<<= | 左移后赋值 | c <<= 2 等于c = c << 2 |
>>= | 右移后赋值 | c >>= 2 等于 c = c >> 2 |
&= | 按位与后赋值 | c &= 2 等于 c = c & 2 |
^= | 按位异后赋值 | c ^= 2 等于 c = c ^ 2 |
|= | 按位或后赋值 | c |= 2 等于 c = c | 2 |
案例:
package main
import(
"fmt"
)
func main() {
a := 9
b := 2
fmt.Printf("交换前a = %v , b = %v \n", a, b)
t := a
a = b
b = t
fmt.Printf("交换后a = %v , b = %v \n", a , b)
a += 17
fmt.Println("a=", a)
}