zoukankan      html  css  js  c++  java
  • Python老男孩 day17 函数(十一) 其他函数

    ord函数
    显示对用的ASCII码值
    print(ord('a'))
    运行结果:
    97
    
    pow函数
    print(pow(2,3)) #2**3
    print(pow(2,3,3)) #2**3%3
    运行结果:
    8
    2
    
    reversed函数
    l=[1,2,3,4]
    print(list(reversed(l)))
    print(l)
    运行结果:
    [4, 3, 2, 1]
    [1, 2, 3, 4]
    
    round函数
    print(round(3.5))
    运行结果:
    4
    
    set函数
    print(set('hello'))
    运行结果:
    {'l', 'h', 'e', 'o'}
    
    slice函数
    l='hello'
    s1=slice(3,5)
    s2=slice(1,4,2)
    print(l[3:5])
    print(l[s1])
    运行结果:
    lo
    lo
    
    print(l[s2])
    print(s2.start) #开始位置
    print(s2.stop) #结束位置
    print(s2.step) #步长
    运行结果:
    el
    1
    4
    2
    
    sorted函数
    l=[3,2,1,5,7]
    print(sorted(l))
    运行结果:
    [1, 2, 3, 5, 7]
    #排序本质就是在比较大小,不同类型不能比较
    
    people=[
        {'name':'alex','age':1000},
        {'name':'wupei','age':10000},
        {'name':'yuanhao','age':9000},
        {'name':'linhaifeng','age':18},
    ]
    print(sorted(people,key=lambda dic:dic['age']))
    运行结果:
    [{'name': 'linhaifeng', 'age': 18}, {'name': 'alex', 'age': 1000}, {'name': 'yuanhao', 'age': 9000}, {'name': 'wupei', 'age': 10000}]
    
    name_dic={
        'abyuanhao': 11900,
        'alex':1200,
        'wupei':300,
    }
    print(sorted(name_dic))
    
    print(sorted(name_dic,key=lambda key:name_dic[key]))
    
    print(sorted(zip(name_dic.values(),name_dic.keys())))
    运行结果:
    ['abyuanhao', 'alex', 'wupei']
    ['wupei', 'alex', 'abyuanhao']
    [(300, 'wupei'), (1200, 'alex'), (11900, 'abyuanhao')]
    
    vars函数
    #vars()里没参数相当于locals()
    def test():
        msg='sadssadsa'
        print(locals())
        print(vars())
    
    test()
    运行结果:
    {'msg': 'sadssadsa'}
    {'msg': 'sadssadsa'}
    
    #vars()带参数,以字典形式显示出对象的所有方法
    print(vars(int))
    运行结果:
    {'__repr__': <slot wrapper '__repr__' of 'int' objects>, '__hash__': <slot wrapper '__hash__' of 'int' objects>, '__str__': <slot wrapper '__str__' of 'int' objects>, '__getattribute__': <slot wrapper '__getattribute__' of 'int' objects>, '__lt__': <slot wrapper '__lt__' of 'int' objects>, '__le__': <slot wrapper '__le__' of 'int' objects>, '__eq__': <slot wrapper '__eq__' of 'int' objects>, '__ne__': <slot wrapper '__ne__' of 'int' objects>, '__gt__': <slot wrapper '__gt__' of 'int' objects>, '__ge__': <slot wrapper '__ge__' of 'int' objects>, '__add__': <slot wrapper '__add__' of 'int' objects>, '__radd__': <slot wrapper '__radd__' of 'int' objects>, '__sub__': <slot wrapper '__sub__' of 'int' objects>, '__rsub__': <slot wrapper '__rsub__' of 'int' objects>, '__mul__': <slot wrapper '__mul__' of 'int' objects>, '__rmul__': <slot wrapper '__rmul__' of 'int' objects>, '__mod__': <slot wrapper '__mod__' of 'int' objects>, '__rmod__': <slot wrapper '__rmod__' of 'int' objects>, '__divmod__': <slot wrapper '__divmod__' of 'int' objects>, '__rdivmod__': <slot wrapper '__rdivmod__' of 'int' objects>, '__pow__': <slot wrapper '__pow__' of 'int' objects>, '__rpow__': <slot wrapper '__rpow__' of 'int' objects>, '__neg__': <slot wrapper '__neg__' of 'int' objects>, '__pos__': <slot wrapper '__pos__' of 'int' objects>, '__abs__': <slot wrapper '__abs__' of 'int' objects>, '__bool__': <slot wrapper '__bool__' of 'int' objects>, '__invert__': <slot wrapper '__invert__' of 'int' objects>, '__lshift__': <slot wrapper '__lshift__' of 'int' objects>, '__rlshift__': <slot wrapper '__rlshift__' of 'int' objects>, '__rshift__': <slot wrapper '__rshift__' of 'int' objects>, '__rrshift__': <slot wrapper '__rrshift__' of 'int' objects>, '__and__': <slot wrapper '__and__' of 'int' objects>, '__rand__': <slot wrapper '__rand__' of 'int' objects>, '__xor__': <slot wrapper '__xor__' of 'int' objects>, '__rxor__': <slot wrapper '__rxor__' of 'int' objects>, '__or__': <slot wrapper '__or__' of 'int' objects>, '__ror__': <slot wrapper '__ror__' of 'int' objects>, '__int__': <slot wrapper '__int__' of 'int' objects>, '__float__': <slot wrapper '__float__' of 'int' objects>, '__floordiv__': <slot wrapper '__floordiv__' of 'int' objects>, '__rfloordiv__': <slot wrapper '__rfloordiv__' of 'int' objects>, '__truediv__': <slot wrapper '__truediv__' of 'int' objects>, '__rtruediv__': <slot wrapper '__rtruediv__' of 'int' objects>, '__index__': <slot wrapper '__index__' of 'int' objects>, '__new__': <built-in method __new__ of type object at 0x00000000538A99E0>, 'conjugate': <method 'conjugate' of 'int' objects>, 'bit_length': <method 'bit_length' of 'int' objects>, 'to_bytes': <method 'to_bytes' of 'int' objects>, 'from_bytes': <method 'from_bytes' of 'int' objects>, '__trunc__': <method '__trunc__' of 'int' objects>, '__floor__': <method '__floor__' of 'int' objects>, '__ceil__': <method '__ceil__' of 'int' objects>, '__round__': <method '__round__' of 'int' objects>, '__getnewargs__': <method '__getnewargs__' of 'int' objects>, '__format__': <method '__format__' of 'int' objects>, '__sizeof__': <method '__sizeof__' of 'int' objects>, 'real': <attribute 'real' of 'int' objects>, 'imag': <attribute 'imag' of 'int' objects>, 'numerator': <attribute 'numerator' of 'int' objects>, 'denominator': <attribute 'denominator' of 'int' objects>, '__doc__': "int(x=0) -> integer
    int(x, base=10) -> integer
    
    Convert a number or string to an integer, or return 0 if no arguments
    are given.  If x is a number, return x.__int__().  For floating point
    numbers, this truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string,
    bytes, or bytearray instance representing an integer literal in the
    given base.  The literal can be preceded by '+' or '-' and be surrounded
    by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
    Base 0 means to interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    4"}
  • 相关阅读:
    ifdef有大用处
    osgEarth编译
    CyanogenMod 7.1 for Sony Ericsson X8 下载 CM7.1 for 索爱X8下载
    ArcGIS影像配准与空间配准
    ArcGIS Server的切图原理深入
    Arcgis server的rest服务url写法解读
    地图切片公式
    新随笔
    solr的java调用
    配置文件
  • 原文地址:https://www.cnblogs.com/zhuhemin/p/9355494.html
Copyright © 2011-2022 走看看