zoukankan      html  css  js  c++  java
  • python基础(3)-----循环

    if循环

    name=["sdf","sadf","awdasd","ljy"]
    for user in name:
        if user=="ljy":
            print(user.upper())#全部大写
        else:
            print(user.title())#首字母大写
    name="ljy"
    if name != "LL": #if不等于
        print("dont mattached")
    
    user="ljy1"
    if user not in name:     #检查特定值是否在列表中
        print(user+" not in name")

    if-else循环

    """if-else简单应用实例"""
    age=18
    if age>=12:
        print("you can go")
    else:
        print("you cant go")
    
    """实例if-elif-else"""
    age=18
    if age<12:
        print("you can go 1 ")
    elif age<18:
        print("you can go 2 ")
    else:
        print("you can go 3 ")
    
    """多个elif代码块"""
    age=18
    if age<12:
        print("you can go 1 ")
    elif age<18:
        print("you can go 2 ")
    elif age<23:
        print("you can go 6 ")
    else:
        print("you can go 3 ")

    while循环

    age=1
    while age<4:
        print(age)
        age +=1

     break和continue

    while 语句时还有另外两个重要的命令 continue,break 来跳过循环,continue 用于跳过该次循环,break 则是用于退出循环

    for i in range (1,3):
        print
        print('i=',i)
        print('Hello,how')
        if i==2:
            break
        print('are you today?')
    

    for i in range (1,3):
        print
        print('i=',i)
        print('Hello,how')
        if i==2:
            continue
        print('are you today?')
    

  • 相关阅读:
    12_常用类
    MyBatis_02 框架
    MyBatis_01 框架
    正则表达式
    11_异常处理
    产品经理成长之路(非原创)
    【Java每日一题】20161115
    【Java每日一题】20161114
    【Java每日一题】20161111
    【Java每日一题】20161110
  • 原文地址:https://www.cnblogs.com/jinyuanliu/p/10341350.html
Copyright © 2011-2022 走看看