name_list = ["夏","商","周","秦","汉","三国"]
num_list = [100,148,186,160,173,184]
#zip函数将迭代器封装成生成器,平行遍历
for rust,ru in zip(name_list,num_list):
print("国家是:%s 年代是:%d"%(rust,ru))
#for ru in num_list:
# print("年代是:%d" % ru)
#取值,查看索引对应的数值
print(name_list[3])
#取索引
print(name_list.index("汉"))
#修改列表数值
name_list[4]="东汉"
print(name_list[4])
#添加内容,添加到尾部
name_list.append("东晋")
#for rust in name_list:
#print("国家是:%s"%rust)
#根据索引添加内容
name_list.insert(3,"春秋战国")
#for rust in name_list:
#print("国家是:%s"%rust)
#将列表nme_list添加给name_list
nme_list = ["唐","宋","元","明","清"]
name_list.extend(nme_list)
#for rust in name_list:
# print("国家是:%s"%rust)
#删除指定的数据
name_list.remove("东晋")
#for rust in name_list:
#print("国家是:%s"%rust)
#根据索引删除数据,如果没有索引,删除最后一个
#给括号内加上索引,删除索引指定的数据
name_list.pop(3)
#for rust in name_list:
#print("国家是:%s"%rust)
#清空列表
#name_list.clear()
#for rust in name_list:
# print("国家是:%s"%rust)
#统计列表的参数总数(函数)
print(len(name_list))
#name_list.append("唐")
#统计列表中重复的参数的个数
print(name_list.count("唐"))
#用remove删除重复的参数时从前往后开始删除
#name_list.remove("唐")
#for rust in name_list:
#print("国家是:%s"%rust)
#将 列表的参数升序排列,reverse=False可以省略
#num_list.sort(reverse=False)
#for ru in num_list:
#print("时间是:%d"%ru)
#将列表的参数降序排列
#num_list.sort(reverse=True)
num_list.reverse()
#for ru in num_list:
# print("时间是:%d"%ru)
name_list = ["人之初","性本善","性相近","习相远","苟不教","性乃迁","教之道","贵以专","昔孟母","择邻处","子不学","断机杼","窦燕山","有义方"]
#print("最后一句是:%s"%name_list[-1])
#删除指定索引的参数
#name_list.__delitem__(1)
#print(name_list[1])
i = 0
for um in name_list:
print(um,end="")
i += 1
if i == 4:
print("")
i = 0
# end= ""取消列表遍历的换行