# 2.3循环结构 # 2.3.1:for循环 # 实例1:遍历列表 test_list=['a',1,2,'c'] for i in test_list: if i==1: print(test_list) else: pass #代表什么都不发生 # 实例2:遍历字典key test_dict={"key":"value","key1":"value1"} for i in test_dict.keys(): if i=="key": print(i) else: print("i!=key") # 实例2:遍历字典value test_dict={"key":"value","key1":"value1"} for i in test_dict.values(): if i=="value": print(i) else: print("i!=key") # 实例3:遍历字典key和value test_dict={"key":"value","key1":"value1"} for key,value in test_dict.items(): if key=="key": print(key,value) else: print("i!=key")
python入门之控制流for循环_09
最新推荐文章于 2024-01-20 23:34:13 发布