第四节 赋值运算

赋值运算包含八种

= 简单赋值

+= 加法赋值,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 **= a相当于c = c ** a

//= 取整赋值,c //= a相当于c = c // a

x = 1
y = 2
print("x的值为:",x)
print("y的值为:",y)
x += y
print("x += y的结果为:",x)
x = 1
y = 2
x -= y
print("x -= y的结果为:",x)
x = 1
y = 2
x *= y
print("x *= y的结果为:",x)
x = 1
y = 2
x /= y
print("x /= y的结果为:",x)
x = 1
y = 2
x %= y
print("x %= y的结果为:",x)
x = 1
y = 2
x **= y
print("x **= y的结果为:",x)
x = 1
y = 2
x //= y
print("x //= y的结果为:",x)

运行结果:

alt 赋值运算

results matching ""

    No results matching ""