zoukankan      html  css  js  c++  java
  • for循环

    #!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 world world say hello guys guys'中每个单词的个数

     

     2统计s = 'hello world world say hello guys guys'中每个单词的个数
    # s = 'hello world world say hello guys guys'
    # 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)
    
  • 相关阅读:
    hdu 1258 DFS
    hdu2488 dfs
    poj1915 BFS
    hdu1372 BFS求最短路径长度
    poj3264 线段树
    hdu 2438Turn the corner 三分
    hdu3714 三分
    【转载】单点登陆
    ajax从入门到深入精通
    Web前端技术体系大全搜索
  • 原文地址:https://www.cnblogs.com/morgana/p/8496410.html
Copyright © 2011-2022 走看看