zoukankan      html  css  js  c++  java
  • python总结

    001 python运算符

    1、算术运算符

    + - * / // ** %
    

    2、比较运算符

    > < == != >= <=
    

    3、逻辑运算符

    and or not 
    
    python中 0、""、[]、()、{}、None为假,其余为真
    and:x为真,x and y结果为y,x为假,x and y结果为x
    or :x为真,x or y 结果为x,x为假,x or y结果为y
    not:x为真,not x结果为False,x为假,not x结果为True
    
    

    4、位运算符

    2个运算数:   &(位与) |(位或) ^(异或) 
    1个运算数:    ~(取反) <<(左位移) >>(右位移)
    
    位运算是直接对二进制字符0,1进行操作
    &:全1为1,否则为0
    |:全0为0,否则为1
    ^:相同为0,相异为1
    
    1:01
    0:00
    1&0:00
    1|0:01
    1^0:01
    
    

    5、赋值运算符

    =
    

    6、成员运算符

    in  not in
    

    7、身份运算符

    is  is not
    

    002 math和cmath

    • math提供了许多对浮点数的数学运算函数
      sin、sqrt、tan等
    int(math.sqrt())显示为整数
    int(cmath.sqrt())报错,复数无法强制为整型
    
    • cmath提供了一些用于复数运算的函数

    003 同时输入多值

    #同时输入多个字符串
    x,y,z=input("输入字符串:").split()   #以空格隔开
    x,y,z=input("输入字符串:").split(",")#以逗号隔开
    #同时输入多个数字
    a,b,c=eval(input("输入数字:"))  #以单引号隔开
    a,b,c=map(int,input("输入数字").split()) #空格隔开
    #改变map里的int,为float,str,输入不同类型的数
    
    sum=[]
    for i in range(3):
        x=int(input("输入数字:"))
        sum.append(x)
    print(sum)
    

    004 时间日期

    import time
    
    print(time.time())  #时间戳
    print(time.ctime()) #将时间戳转为字符串
    print(time.localtime()) #将时间戳转换为struct_time类型本地时间
    print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
    
    # python中时间日期格式化符号:
    # %y 两位数的年份表示(00-99)
    # %Y 四位数的年份表示(000-9999)
    # %m 月份(01-12)
    # %d 月内中的一天(0-31)
    # %H 24小时制小时数(0-23)
    # %I 12小时制小时数(01-12) 
    # %M 分钟数(00=59)
    # %S 秒(00-59)
    
    # 1589462975.5584602
    # Thu May 14 21:29:35 2020
    # time.struct_time(tm_year=2020, tm_mon=5, tm_mday=14, tm_hour=21, tm_min=29, tm_sec=35, tm_wday=3, tm_yday=135, tm_isdst=0)
    # 2020-05-14 21:29:35
    
  • 相关阅读:
    替换URL传递的参数
    执行SQl语句得到xml结果集
    table中文本太长换行
    org.xml.sax.SAXNotRecognizedException
    WAMP+CMSeasy快速搭建学校网站
    推荐几个web前台开发的小工具
    来园子里注册啦
    C++ Virtual的背后
    Games101观后补充笔记
    Lua语法入门
  • 原文地址:https://www.cnblogs.com/observering/p/12891522.html
Copyright © 2011-2022 走看看