zoukankan      html  css  js  c++  java
  • 内置函数(十)

    #!/usr/bin/python3
    
    print(ord('a'))    # 转数字
    
    print(pow(3, 3)) # 取次方
    print(pow(3, 3, 2))# 取次方再对2求余数
    
    '''
    97
    27
    1
    '''
    #!/usr/bin/python3
    
    str = 'hello'
    s1 = slice(2,4)
    s2 = slice(0,5,2) # z指定步长为2
    print(str[s1])
    print(str[s2])
    
    '''
    ll
    hlo
    '''

    http://www.runoob.com/python3/python3-built-in-functions.html

    str = '你好'
    print(bytes(str, encoding='utf-8')) # b'xe4xbdxa0xe5xa5xbd'
    print(bytes(str, encoding='utf-8').decode('utf-8')) # 你好
    print(bytes(str, encoding='gbk')) # b'xc4xe3xbaxc3'
    print(bytes(str, encoding='gbk').decode('gbk'))
    
    print(divmod(10, 3)) # (3, 1) 十除三,得三余一 可做分页功能
    
    str2 = "{'name': 'a'}" # 字符串里面有字典的串
    print(str2) # {'name': 'a'}
    print(eval(str2)) # {'name': 'a'} 将字典解析出来
    express = '1+3*2'
    print(eval(express)) # 7
    
    # 可hash的数据类型即不可变数据类型,不可hash的数据类型即可变数据类型
    name = 'hello'
    print(hash(name))  # 3576857839363168520
    print(hash(name))  # 3576857839363168520
    print(hash(name))  # 3576857839363168520
    
    print(bin(10)) # 0b1010
    print(hex(10)) # 0xa
    print(oct(10)) # 0o12
    abs()
    dict()
    help()
    min()
    setattr()
    all()
    dir()
    hex()
    next()
    slice()
    any()
    divmod()
    id()
    object()
    sorted()
    ascii()
    enumerate()
    input()
    oct()
    staticmethod()
    bin()
    eval()
    int()
    open()
    str()
    bool()
    exec()
    isinstance()
    ord()
    sum()
    bytearray()
    filter()
    issubclass()
    pow()
    super()
    bytes()
    float()
    iter()
    print()
    tuple()
    callable()
    format()
    len()
    property()
    type()
    chr()
    frozenset()
    list()
    range()
    vars()
    classmethod()
    getattr()
    locals()
    repr()
    zip()
    compile()
    globals()
    map()
    reversed()
    __import__()
    complex()
    hasattr()
    max()
    round()
     
    delattr()
    hash()
    memoryview()
    set()
  • 相关阅读:
    find . name "*.py" print | xargs.exe grep py
    opensource license 的区别图解
    python urllib2 httplib HTTPConnection
    【转帖】使用python爬虫抓站的一些技巧总结:进阶篇
    ssh keyboard interactive
    using Net::SSH2 shell method
    【转帖】用python爬虫抓站的一些技巧总结
    PySide QtWebKit 读取网页
    qt single instance solution for PySide qt 4.7
    vim 首字符注释自动取消缩进问题
  • 原文地址:https://www.cnblogs.com/xiangtingshen/p/10390537.html
Copyright © 2011-2022 走看看