在了解了赋值运算符之后编写实例进行验证,在basis目录下新建文件,命名为assignment.py,学习Python赋值运算符的操作,在PyCharm中输入代码。
operand_a = 5
operand_b = 2
operand_c = 0
简单的赋值
operand_c = operand_a
print("{} = {}:".format(operand_c, operand_a))
print("{} = {}".format("operand_c", operand_c))
加法赋值
operand_c = operand_a
print("{} += {}:".format(operand_c, operand_b))
operand_c += operand_b
print("{} = {}".format("operand_c", operand_c))
减法赋值
operand_c = operand_a
print("{} -= {}:".format(operand_c, operand_b))
operand_c -= operand_b
print("{} = {}".format("operand_c", operand_c))
乘法赋值
operand_c = operand_a
print("{} = {}:".format(operand_c, operand_b))
operand_c = operand_b
print("{} = {}".format("operand_c", operand_c))
除法赋值
operand_c = operand_a
print("{} /= {}:".format(operand_c, operand_b))
operand_c /= operand_b
print("{} = {}".format("operand_c", operand_c))
取余赋值
operand_c = operand_a
print("{} %= {}:".format(operand_c, operand_b))
operand_c %= operand_b
print("{} = {}".format("operand_c", operand_c))
取整赋值
operand_c = operand_a
print("{} //= {}:".format(operand_c, operand_b))
operand_c //= operand_b
print("{} = {}".format("operand_c", operand_c))
乘幂赋值
operand_c = operand_a
print("{} = {}:".format(operand_c, operand_b))
operand_c = operand_b
print("{} = {}".format("operand_c", operand_c))