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?')
    

  • 相关阅读:
    发送ajax步骤
    web app开发技巧总结
    移动端常见问题及解决方案
    【转】Session Cookie Token的区别
    call、apply、bind的区别
    【转】rem自适应布局
    ThinkPHP系统内置单字母函数函数
    thinkphp buildsql和fetchsql的区别
    thinkphp 3.2.3重写 pdo链接
    thinkphp pdo 重写问题
  • 原文地址:https://www.cnblogs.com/jinyuanliu/p/10341350.html
Copyright © 2011-2022 走看看