1#链式比较
a=3
b=1
print(1<=b<=a<10)
2#真值测试:0、''、None、False、空容器[](){}为假
name = 'Tim'
langs = ['AS3', 'Lua', 'C']
info = {'name': 'Tim', 'sex': 'Male', 'age':23 }
if name and langs and info:
print('All True!') #All True!
3#包含和迭代
name = 'Safe Hammad'
if 'H' in name:
print('This name has an H in it!')
pets = ['Dog', 'Cat', 'Hamster']
for pet in pets:
print('A', pet, 'can be very cute!')
4#字符串反转:str(::-1)
5#连接:字符串列表
strList = ["Python", "is", "good"]
res = ' '.join(strList)
6#EAFP优于LBYL
7#列表求和,最大值,最小值,乘积
numList = [1,2,3,4,5]
sum = sum(numList)
maxNum = max(numList)
minNum = min(numList)
from operator import mul
from functools import reduce
prod = reduce(mul, numList, 1)
8#各种推导式
9#while...else和for...else语句
10# 三元符的替代
a=3
b=2 if a>2 else 1
11#enumerate
12#zip
13#with
14#替换
a,b=b,a
15#分解
lis = ['David', 'Pythonista', '+1-514-555-1234']
first_name, last_name, phone_number = lis
16#in替代or
fruit="berry"
if fruit in("apple","orange"):pass
#相当于if fruit == "apple" or fruit == "orange":paas
17#字典setdefault方法
18#product
# from itertools import product
# for x, y, z in product(x_list, y_list, z_list):pass
##相当于
# for x in x_list:
# for y in y_list:
# for z in z_list:
# paas
19#yeild
20#魔法函数