列表生成器


将list1中的值,依次取出,添加到new_list中

list1 = [1,2,3,4]
new_list = []
for line in list1:
new_list.append(line)
print(new_list)

new_list = []
for line in range(1,10):
new_list.append(line)
print(new_list)


列表生成式
举例

name_list = ['jason', '饼哥(大脸)', 'sean', 'egon']

new_name_list = [name + '_dsb' for name in name_list]

print(new_name_list)
posted @ 2019-11-18 19:31  medigrat  阅读(169)  评论(0编辑  收藏  举报