美文网首页
python基础1_变量_运算符_if-else

python基础1_变量_运算符_if-else

作者: 灵秋公子 | 来源:发表于2020-01-04 09:17 被阅读0次

    变量:存储信息的,日后被调用,修改操作

    常量:固定不变的量,字母大写

    命名规则:{

    1. 字母数字下划线组成

    2. 不能以数字开头,不能含有特殊字符和空格

    3. 不能以保留字命名

    4. 不能以中文命名

    5. 定义的变量名应该有意义

    6. 驼峰式命、 下划线分割单词

    7. 变量名区分大小写

    }

    a=1
    
    b=2
    
    if  a<b:
    
        print("Yes")
    
        print("Yes")
    
        print("Yes")
    
        print("Yes")
    
    else:
    
        print("No")
    
    a=1
    
    b=2
    
    if a>b:
    
        print("Yes")
    
    elif a==b:
    
        print("第三")
    
    else:
    
        print("any")
    

    单行注释,多行注释

    (#)单行注释
    '''多行注释'''
    """ 多行注释 """

    input()用户命令行输入

    name = input("")

    if_else

    if  b <= a <= c:
        print("True")
    num  number
    num1 = intpu("Num1:")
    num2 = intpu("Num2:")
    num3 = intpu("Num3:")
    
    输出三个数字中的最大值/最小值
    num1 num2 num3
    max_num =0
    if num1>num2:
        max_num= num1
        if max_num > num3:
            print("Max NUM is",max_num)
        else:
            print("Max NUM is",num3)
    else:
        max_num = num2
        if max_num > num3:
            print("Max NUM is",max_num)
        else:
            print("Max NUM is",num3)
    

    运算符

    num += 1  等价于 num = num + 1
    num -= 1  等价于 num = num - 1
    num *= 2  等价于 num = num * 2
    num /= 2  等价于 num = num / 2
    num //= 2  等价于 num = num // 2
    num %= 2  等价于 num = num % 2
    num **= 2  等价于 num = num ** 2
    

    and

    且,并且只有两个条件全部为True(正确的时候, 结果才会为True(正确)

    条件1 and 条件2
       5>3 and 6<2  True
    

    or

    只要有一个条件为True,则结果为Ture,
    5>3 or 6<2

    not

    不(取相反的数值)

    not 5>3  == False
    not 5<3  == True
    a>b and (c>d or (not f))
    (not (not True)) or (False and (not True))
    
    if a>b  and  d<f or  5>3  and  d == e:
        ......
    

    短路原则

    对于and 如果前面的第一个条件为假,那么这个and前后两个条件组成的表达式 的计算结果就一定为假,第二个条件就不会被计算

    对于or
    如果前面的第一个条件为真,那么这个or前后两个条件组成的表达式 的计算结果就一定为真,第二个条件就不会被计算

    相关文章

      网友评论

          本文标题:python基础1_变量_运算符_if-else

          本文链接:https://www.haomeiwen.com/subject/judxactx.html