python基础笔记 发表于 2019-10-20 | 更新于 2023-01-11 ==和is1234567# == 和 !=比较的是赋值是否相等# is 和 not比较的是id是否相等,是否是同一个对象a = [1, 2, 3]b = [1, 2, 3]print(a == b)print(a is b)print(id(a), id(b)) range 序列12345678910# range: 起始位置、结束位置、步长print(range(3, 10))print(list(range(3, 10, 2)))r = range(10)print(r)print(list(r))# 通过range进行for 循环for i in range(100): print(i) while 语句123456789101112131415161718192021222324# while语句i = 0total = 0while i < 100: i += 1 total += iprint(total)# breaki = 0while i < 100: i += 1 if i > 50: breakprint(i)# continuei = 0while i < 100: i += 1 if i % 10: continue print(i) 三元运算1234a = 1b = 2max = a if (a > b) else bprint(m)