算术运算符不仅有加'+'减'-'乘'*'除'/',还有整除'//',取余'%',等于'='。
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)