• for 循环


    # for 循环

    while循环是可控,但是控制不好是不是就是一个死循环。

    ```python
    wenyi_info_list = ['AA','BB','CC','DD','EE']
    print(wenyi_info_list[0])
    print(wenyi_info_list[1])
    print(wenyi_info_list[2])
    ```

    ```
    AA
    BB
    CC
    ```

    ```python
    wengyi_info_list = ['AA','BB','CC']
    len(wengyi_info_list)
    ```

    ```
    3
    ```

    ```python
    wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    count = 0
    while count < len(wenyi_info_list):
    print(wenyi_info_list[count])
    count += 1
    ```

    ```
    wenyi
    150
    260
    ['piao', '666', 'fish']
    zhangdechou
    1
    2
    3
    4
    5
    6
    67
    ```

    ```python
    wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    for i in wenyi_info_list:
    print(i)
    ```

    ```
    wenyi
    150
    260
    ['piao', '666', 'fish']
    zhangdechou
    1
    2
    3
    4
    5
    6
    67
    ```

    # for+break

    ```python
    wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    for i in wenyi_info_list:
    if i == 'zhangdechou':
    break
    print(i)
    ```

    ```
    wenyi
    150
    260
    ['piao', '666', 'fish']
    ```

    # for+continue

    ```python
    wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    for i in wenyi_info_list:
    if i =='zhangdechou':
    continue
    print(i)
    ```

    ```
    wenyi
    150
    260
    ['piao', '666', 'fish']
    1
    2
    3
    4
    5
    6
    67
    ```

    # for else 如果for循环没有被break掉,则会运行else下面的代码

    ```python
    wenyi_info_list = ['wenyi', 150, 260, ['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    for i in wenyi_info_list:
    if i == 260:
    break
    print(i)
    else:
    print('我没有被break')
    ```

    ```
    wenyi
    150
    ```

    ```python
    wenyi_info_list = ['wenyi', 150,['piao', '666', 'fish'],'zhangdechou',1,2,3,4,5,6,67,]
    for i in wenyi_info_list:
    if i == 260:
    break
    print(i)
    else:
    print('我没有被break')
    ```

    ```
    wenyi
    150
    ['piao', '666', 'fish']
    zhangdechou
    1
    2
    3
    4
    5
    6
    67
    我没有被break
    ```

    # while和for循环异同

    异:while循环需要条件,for循环不需要条件
    同:都是循环

    # for循环实现loading......

    ```python
    for i in range(0,6):
    print('.')
    ```

    ```
    .
    .
    .
    .
    .
    .
    ```

    ```python
    for i in range(0,6):
    print('.',end = '')
    ```

    ```
    ......
    ```

    ```python
    import time
    s = 'loading'
    print(s,end = '')
    for i in range(0,6):
    print('#',end='')
    time.sleep(1)#字符出现时间间隔1秒
    ```

    ```
    loading######
    ```

    ```python
    import time
    for i in range(0,6):
    if i == 0:
    print('[#',end = '')
    if i == 4:
    print('#]',end = '')
    print('#',end = '')
    time.sleep(0.5)
    ```

    ```
    [######]##
    ```

    ```python

    ```

  • 相关阅读:
    spring cloud的pigx版本
    SQL Profiler使用
    postmen简单用法
    T-SQL
    常见问题整理
    数据库 新建维护计划
    c# ABP返回格式自定义,去除固定返回格式
    系统综合实践期末大作业 第32组
    系统综合实践第7次实践作业 第32组
    系统综合实践第6次实践作业 第32组
  • 原文地址:https://www.cnblogs.com/zrx19960128/p/10823329.html
Copyright © 2020-2023  润新知