python_条件语句

条件语句

  • Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。

  • Python程序语言指定任何非0和非空(null)值为true,0 或者 null为false。

  • Python 编程中 if 语句用于控制程序的执行,基本形式为:

    if 判断条件:
       执行语句……
    else
       执行语句……
  • 案例实操

    [root@slave2 pythontest]# vim if.py
    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    flag = False
    name = 'luren'
    if name == 'python':
       flag = True
       print 'welcome boss'
    else:
       print name
    ~                
    [root@slave2 pythontest]# chmod 777 if.py
    [root@slave2 pythontest]# ll
    total 4
    -rwxrwxrwx. 1 root root 152 Jan 23 07:17 if.py
    [root@slave2 pythontest]# ./if.py
    luren
原文地址:https://www.cnblogs.com/zxbdboke/p/10468183.html