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

    if 判断

    if

    if  条件 :
    	代码块
    	
    
    nums = 0
    if  nums < 3:
        print('hello')
    

    if else:

    if    条件:
        代码块
    else:
        代码块
    
    nums = int(input('输入数字:'))
    if nums < 10 :
        print('hello')
    else:
        print('dada')
    

    if elif else

    if  条件 :
        代码块
    elif   条件  :
    	代码块
    else:
        代码块
    
    
    nums = int(input('输入数字:'))
    if nums < 10 :
        print('hello')
    elif nums == 18 :
        print('gang he shi')
    else:
        print('闪开')
    

    while 循环

    while

    while   条件  :
    	代码块
    
    nums = 0
    while  nums < 10:
        print('来啦,老弟')
        nums += 1
    

    while break continue

    nums = 0
    while nums < 5:
        print(nums)
        break   # 直接结束所属循环
    
    nums = 0 
    while nums < 5:
        print(nums)
        continue  # 直接返回所属循环首部,再次开始循环,后面的代码不再执行
        nums += 1
    

    for

    # range(1,10) 1-9的数字   i  从range中一次一个取值,直到range中的值全部被取一次
    for i in range(1,10):
        print(i)
    

    for循环的次数受限于容器类型的长度,for循环可以按索引取值。

    for break

    break 可以直接结束当前循环

    for i in range(10):
        print(i)
        break
    

    for continue

    continue 直接结束本次循环,返回所属循环首部,开始下一次循环

    for i in range(10):
        continue
        print(i)
    
  • 相关阅读:
    jQuery Lazy Load 图片延迟加载
    jquery多级联动(ajax查数据库)
    在命令行快速切换目录(转载)
    推荐Mac软件Alfred
    Vim的snipMate插件
    腾讯CMEM的PHP扩展(转载)
    svn hooks使用
    samba基本配置
    linux进程状态详解(转)
    elk systemd管理
  • 原文地址:https://www.cnblogs.com/fengxuemuyangren/p/10908315.html
Copyright © 2011-2022 走看看