python-day8-循环补充

# msg='hello'
# msg=[1,2,3,4,5,6]
# msg=(1,2,3,4,5,6)



# index=0
# while index < len(msg):
# print(msg[index])
# index+=1

# msg_dic={
# 'apple':10,
# 'tesla':1000000,
# 'mac':3000,
# 'lenovo':30000,
# 'chicken':10,
# } #无序,用索引就不适用了

# msg='hello'
# # msg=['a','b','c','d','e']
# msg=('a','b','c','d','e')
#
# for i in range(len(msg)):
# print(i,msg[i])




#不依赖索引的取值
# for item in msg_dic:
# print(item,msg_dic[item])

# msg='hello'
# msg=[1,2,3,4,5,6]
# msg=(1,2,3,4,5,6)
# for item in msg:
# print(item)

#补充
#range:顾头不顾尾,默认从0开始
# print(type(range(1,2)))
# for i in range(10):
# print(i,type(i))

# for i in range(1,10,2):
# print(i,type(i))

# for i in range(10,1,-2):
# print(i)


# for i in range(1,10,1):
# print(i)

# for i in range(9,0,-1):
# print(i)



#break
#continue


# for i in range(10):
# if i == 4:
# # break
# continue
# print(i)


#for+else
# for i in range(10):
# print(i)
# break
# else: # 最后执行,并且在没有被break打断的情况下才执行
# print('===>')


# 作业:99乘法表
posted @ 2017-07-20 16:21  Cool·  阅读(163)  评论(0编辑  收藏  举报