zoukankan      html  css  js  c++  java
  • python学习-10 运算符1

    1.加+,减-,乘*,除/

    例如:

    a = 1
    b = 2
    c = a + b
    print(c)

    运算结果:

    3
    
    Process finished with exit code 0
    a = 1
    b = 2
    c = a - b
    print(c)

    运算结果:

    -1
    
    Process finished with exit code 0
    a = 1
    b = 2
    c = a * b
    print(c)

    运算结果:

    2
    
    Process finished with exit code 0
    a = 1
    b = 2
    c = a / b
    print(c)

    运算结果:

    0.5
    
    Process finished with exit code 0

    2.特殊的 幂 **, 取余%,//取商

    例如:

    a = 1
    b = 2
    c = a ** b
    print(c)

    运算结果:

    1
    
    Process finished with exit code 0
    a = 9
    b = 2
    c = a % b
    print(c)

    运算结果:

    1
    
    Process finished with exit code 0
    a = 9
    b = 2
    c = a // b
    print(c)

    运算结果:

    4
    
    Process finished with exit code 0

    3.in 和 not in 表示判断

    判断某个东西是否在**里

    例如:

    in  

    name = 'abd'        #'abd'  字符串  ; 'a' 字符
    if 'a' in name:     #   如果a在name里
        print('ok')
    else:
        print('error')

    运行结果:

    ok
    
    Process finished with exit code 0

    ps:

    子字符串:

    name = 'abd'        #'abd'  字符串  ; 'a' 字符
    #'bd'  子字符串或者叫子序列
    if 'ad' in name:     #   如果a在name里
        print('ok')
    else:
        print('error')

    运行结果:

    error
    
    Process finished with exit code 0

    not in:

    name = 'abd'
    if 'a' not in name:
        print('ok')
    else:
        print('error')

    运行结果:

    error
    
    Process finished with exit code 0
  • 相关阅读:
    对路径“E:AnyWiseUnitBusiXtCalXtCal.SiteMain”的访问被拒绝。
    CentOS Docker 安装
    linux命令检查网络问题
    MYSQL命令(二)
    极简技术简录-HTTP
    Java遍历List、Map的集合方法
    jdbc连接数据库并插入一条带有日期的数据
    MYSQL命令(一)
    JDBC连接MySQL数据库批量插入数据
    观察者模式
  • 原文地址:https://www.cnblogs.com/liujinjing521/p/11020423.html
Copyright © 2011-2022 走看看