Python基本运算符
一、算术运算符
算术运算符不仅有加\'+\'减\'-\'乘\'*\'除\'/\',还有整除\'//\',取余\'%\',等于\'=\'。
print(9 // 6)
print(9 % 6)
print(9 + 6)
print(9 - 6)
print(9 * 6)
print(9 / 6)
print(9 == 6)
二、赋值运算符
- 增量赋值
x = 100
x += 50 # :x = x + 50
print(x)
y = 100
y -= 50 # :y = y - 50
print(y)
z = 100
z *= 50 # :z = z * 50
print(z)
q = 100
q /= 50 # :q = q / 50
print(q)
- 链式赋值
a = 999
b = a
c = a
print(a, b, c) # :打印变量\'a\'\'b\'\'\'c\'的值
a = b = c # :简化写法
print(a, b, c) # :打印变量\'a\'\'b\'\'\'c\'的值
- 交叉赋值
v = 3.141592653
w = 1234567890
tmp = v # :创建一个临时变量名\'tmp\'
v = w
w = tmp
print(v, w)
v, w = w, v # :简化写法
print(v, w)
- 解压赋值
分步解压
student_height_list = [\'175cm\', \'180cm\', \'177cm\', \'187cm\', \'190cm\', \'188cm\', \'185cm\'] # :创建学生身高列表
student_height1 = student_height_list[0]
print(student_height1)
student_height2 = student_height_list[1]
print(student_height2)
student_height3 = student_height_list[2]
print(student_height3)
student_height4 = student_height_list[3]
print(student_height4)
student_height5 = student_height_list[4]
print(student_height5)
student_height6 = student_height_list[5]
print(student_height6)
student_height7 = student_height_list[6]
print(student_height7)
一步到位
student_height_list = [\'175cm\', \'180cm\', \'177cm\', \'187cm\', \'190cm\', \'188cm\', \'185cm\'] # :创建学生身高列表
height1, height2, height3, height4, height5, height6, height7 = student_height_list
print(height1, height2, height3, height4, height5, height6, height7)
来源:https://www.cnblogs.com/longlive/p/15965999.html
本站部分图文来源于网络,如有侵权请联系删除。