目录在最上面
一、学习内容概括:
学习地址:https://tianchi.aliyun.com/specials/promotion/aicamppython
这一节主要学习到的内容有:
- 变量、运算符与数据类型
- 位运算
- 条件语句
- 循环语句
- 异常处理
二、值得注意内容:
值得注意的内容记录如下:
1. 三元运算符
x, y = 4, 5
if x < y:
small = x
else:
small = y
print(small) # 4
以上的条件判断和赋值操作,可以用以下一条三元运算符来完成:
x, y = 4, 5
small = x if x < y else y
print(small) # 4
2. is、is not 运算符
比较的两个变量均指向不可变类型。
a = "hello"
b = "hello"
print(a is b, a == b) # True True
print(a is not b, a != b) # False False
比较的两个变量均指向可变类型。
a = ["hello"]
b = ["hello"]
print(a is b, a == b) # False True
print(a is not b, a != b) # True False
值得注意的是
– is, is not 对比的是两个变量的内存地址
– ==, != 对比的是两个变量的值
– 比较的两个变量,指向的都是地址不可变的类型(str等),那么is,is not 和 ==,!= 是完全等价的。
– 对比的两个变量,指向的是地址可变的类型(list,dict,tuple等),则两者是有区别的。
3. print() 函数
print(*objects, sep=' ', end='\n', file=sys.