zoukankan      html  css  js  c++  java
  • 【python】理解循环:for,while

    先看下for结构:

    #!/usr/bin/python
    # -*- Coding:UTF-8 -*-
    
    for i in range(1):
        print i

    输出:

    0

    输入和输出:

    #!/usr/bin/python
    # -*- Coding:UTF-8 -*-
    
    for i in range(1, 10):
        print i

    #输出: 1 2 3 4 5 6 7 8 9

    输入和输出:

    #!/usr/bin/python
    # -*- Coding:UTF-8 -*-
    
    for i in range(1, 10, 2):
        print i,
    
    #输出:1 3 5 7 9

    总结:

    range([start=0], stop, [step=1])函数的含义:

    1,从start开始,到stop结束,步长是step;

    2,如果range只有一个参数,那么从0开始到stop-1结束;

    3,step默认步长是1,可以重新写入为2或者更多;

    4,起点包含start,终点不包含stop,到stop-1截止(start <= i < stop)

  • 相关阅读:
    Python学习4
    Python学习3
    Python学习2
    表空间
    sqlplus常用设置
    HashMap和LinkedHashMap
    堆栈源码
    观察者模式
    策略模式
    java线性表
  • 原文地址:https://www.cnblogs.com/helww/p/6780921.html
Copyright © 2011-2022 走看看