标签:变量 指定 基本运算符 pre 算数 链式 算数运算 运算符 赋值
# 1.算数运算符
import b as b
x = 10
y = 3.1
z = 3
print(x + y)
print(x*z)
print(x/z) # 结果带小数
print(x//z) # 结果只保留整数
print(x % z) # 取模,取余数
print(x**z) # 取幂
# 2.比较运算
print(x > y)
print(x < y)
print(x == y)
print(x != y)
print(x >= y)
print(x <= y)
# 3.赋值运算
a = 1 # 变量赋值
# 增量赋值
bb = 10
bb += 1 # bb = bb + 1
bb *= 2 # bb = bb * 2
bb /= 2 # bb = bb / 2
bb %= 3 # bb = bb % 3
bb **= 4 # bb = bb ** 4
print(bb)
# 链式赋值
a1 = b1 = c1 = 10
print(a1, b1, c1)
print(id(a1), id(b1), id(c1))
# 交叉赋值
m = 10
n = 20
print(m, n)
# temp = m
# m = n
# n = temp
# print(m, n)
m, n = n, m
print(m, n)
# 解压赋值
# 列表
salaries = [111, 222, 333, 444]
# 取前面n个值
x, y, z, *_ = salaries # *_:存储列表中所有未被指定的值
print(x)
print(y)
print(z)
# 取后面n个值
*_, x, y, z = salaries # *_:存储列表中所有未被指定的值
print(x)
print(y)
print(z)
# 字典
dic = {‘a‘: 1, ‘b‘: 2, ‘c‘: 3}
x, y, z = dic # 默认解压出来的是key
print(x, y, z)
标签:变量 指定 基本运算符 pre 算数 链式 算数运算 运算符 赋值
原文地址:https://www.cnblogs.com/wyless/p/14930132.html