列表生成式和三元表达式(python3入门)

 1 #一行代码编写一个列表
 2 li = ['%s_qqq'%i for i in range(1,11) if i > 4]
 3 print(li)
 4 
 5 
 6 
 7 x =input('>>')
 8 y = input('>>')
 9 #一行代码做判断并得出所要的结果
10 res = x if x > y else y
11 print(res)

猜你喜欢

转载自www.cnblogs.com/lich1x/p/10029694.html