#!usr/bin/env python
# -*- coding:utf-8 -*-
# dic={
#     'apple':10,
#     'iphon':5000,
#     'wwatch Tv':3000
# }
# for i in dic:
#     print(i,dic[i])

msg=('a','b','c','d')
for i in range(len(msg)):
    print(i)

# for循环不依赖索引取值
    msg_dic = {
        'apple': 20,
        'phone': 2000,
        'banana': 10,
    }
# 例如:
for item in msg_dic:
     print(item, msg_dic[item])

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

for i in range(1, 10,2):# 步长为2
    print(i)

for i in range(10, 1,-1):  # 倒着走
    print(i)

一、九九乘法表打印:
打印99乘法表
# for i in range(1,10):
#     for j in range(1,i+1):
#         print('%s*%s=%s'%(i,j,i*j),end=' ')
#     print()

 二、统计s = 'hello alex alex say hello sb sb'中每个单词的个数

 

 2统计s = 'hello alex alex say hello sb sb'中每个单词的个数
# s = 'hello alex alex say hello sb sb'
# l=s.split()
# print(l)
# dic = {}
# for item in l:
#     if item in dic:
#         dic[item]=dic[item]+1
#     else:
#         dic[item]=1
# print(dic)

  

posted on 2017-07-20 19:15  海燕。  阅读(926)  评论(1编辑  收藏  举报