zoukankan      html  css  js  c++  java
  • python学习-31 内置函数

    内置函数

    1.abs()  绝对值

    2.all()    判断列表里的所有值的布尔值(如果迭代列表里的每个值后都是True 则返回True)

    print(all([1,2,'1']))

    运行结果:

    True
    
    Process finished with exit code 0

    3.any() 与all相反 ,如果有一个为真 都为真

    4.bin() 十进制转换为二进制

    5.bool() 判断布尔值  。为False的布尔值(空,None,0)

    6.bytes()  将字符串转换成字节

    name = '小明'
    print(bytes(name,encoding='utf-8'))

    运行结果:

    b'xe5xb0x8fxe6x98x8e'           # 6个字节
    
    Process finished with exit code 0

    7.decode 解码   (ASCII 不能编码中文)

    name = '小明'
    print(bytes(name,encoding='utf-8').decode('utf-8'))
    print(bytes(name,encoding='gbk').decode('gbk'))

    运行结果:

    小明
    小明
    
    Process finished with exit code 0

    8.chr()   按照ASCII表 打印

    9.dir()  目录

    print(dir(all))

    运行结果:

    ['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']
    
    Process finished with exit code 0

    10.divmod()   取商和余     

    print(divmod(4,2))    # 可以用来做分页功能,例如:一共4页,每页分了2行字,一共分了2页。

    运行结果:

    (2, 0)
    
    Process finished with exit code 0

    11.eval() 提取字符串中的数据结构,还可以把字符串中的表达式进行运算

    12.hash()   可hash的数据类型,为不可变数据类型

    print(hash("113123123465"))
    print(hash("456asdfa4561sdf1a456sad4f"))

    运行结果:

    714133531
    -1932136269
    
    Process finished with exit code 0

    13.help() 查看帮助

    14.hex()  十进制转十六进制

    15.oct()  十进制转八进制

    16.isinstance()   判断类型

    print(isinstance(1,int))

    运行结果:

    True
    
    Process finished with exit code 0

    17.locals()  打印当前路径  (局部)

    18.globals()  打印路径(当前文件的路径)

    19.max() 取最大值

    20.min()取最小值

  • 相关阅读:
    AVR开发 Arduino方法(六) 内存子系统
    AVR开发 Arduino方法(五) 模数转换子系统
    AVR开发 Arduino方法(四) 串行通信子系统
    AVR开发 Arduino方法(三) 定时/计数器子系统
    AVR开发 Arduino方法(二) 中断子系统
    2014.5.17—所谓生活,就是让自己变得更好
    2014.5.10—做事分清时间地点
    2014.5.7—社交网络用户心理分析
    2014.5.7—20岁这几年
    2014.5.5—反向绑定域名,无需工信部备案
  • 原文地址:https://www.cnblogs.com/liujinjing521/p/11160388.html
Copyright © 2011-2022 走看看