84669 人が学習中
152542 人が学習中
20005 人が学習中
5487 人が学習中
7821 人が学習中
359900 人が学習中
3350 人が学習中
180660 人が学習中
48569 人が学習中
18603 人が学習中
40936 人が学習中
1549 人が学習中
1183 人が学習中
32909 人が学習中
小伙看你根骨奇佳,潜力无限,来学PHP伐。
years=['2016','2014','2013','2009','2005'] msg = ['This year is %s' % k for k in years] print msg
这个正好算是Python语言精练的一个特点了:可以很容易根据已有的“容器”构建新的“容器”。容器指的是list/tuple/dict/iter 之类的实现了__iter__方法的类型。
__iter__
比如想要构建字典:
print {k: int(k) for k in years} # 该写法在Python2.7以后支持 # 输出: {'2014': 2014, '2016': 2016, '2005': 2005, '2013': 2013, '2009': 2009}
years = ['2016', '2014', '2013', '2009', '2005'] msg = map(lambda a: "This year is {0}".format(a), years) print(msg)
这个正好算是Python语言精练的一个特点了:可以很容易根据已有的“容器”构建新的“容器”。容器指的是list/tuple/dict/iter 之类的实现了
__iter__
方法的类型。比如想要构建字典: