python 学习笔记(三)

逻辑判断 if ,用法可参考java中if的用法

 

循环 

#循环打印10次 hello world

for x in range(10)

   print('hello wolrd %d', i)

 

#遍历一个list,方法1 

list1 =[1,2,3,4,5,6]

for x in list1:

  print (x)

 

#遍历一个list,方法2

list1 =[1,2,3,4,5,6]

for x in range(len(list1)):

  print (list[x])

 

#遍历一个dict 获取key

dict1 = {‘a’:1,'b':2,'c':3}

for key in dict1.keys()

  print(key)

 

#遍历一个dict 获取values

dict1 = {‘a’:1,'b':2,'c':3}

for key in dict1.keys()

  print(dict1.get(key))

  

 

posted @ 2018-03-14 23:38  凤凤1029  阅读(142)  评论(0编辑  收藏  举报