zoukankan      html  css  js  c++  java
  • Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()

    print('abs():输出绝对值,是absolute的缩写--------------')
    print(abs(-1))
    
    print('all()与any()---------------------------')
    #all都为真时才为真,但是空的为真,any()有一个为真时就是真的
    jo1_list=[1,2,3,4,5,6,7]
    jo2_list=['',2,3,4,5,7]
    jo4_list=[0,2,3,4,5,6,7]
    jo5_list=[False,2,3,4,5,6,7]
    jo6_list=[]
    jo7_list=[0,'',False]
    print('all()列表元素不为空和零',all(jo1_list))
    print('all()列表元素包含一个空',all(jo2_list))
    print('all()列表元素包含一个0',all(jo4_list))
    print('all()列表元素包含一个False',all(jo5_list))
    print('all()列表元素为空',all(jo6_list))
    print('all()列表元素为空、零和假',all(jo7_list))
    
    print('any()列表元素不为空和零',any(jo1_list))
    print('any()列表元素包含一个空',any(jo2_list))
    print('any()列表元素包含一个0',any(jo4_list))
    print('any()列表元素包含一个False',any(jo5_list))
    print('any()列表元素为空',any(jo6_list))
    print('all()列表元素为空、零和假',any(jo7_list))
    
    print('ascii()-----------------------')
    print('参数为数字,返回字符串',ascii(10))
    print('参数为字符串,返回字符串',ascii('jojojo'))
    print('参数为汉字,返回字符串',ascii('呵呵哒'))
    
    print('bin()是binary的缩写--------------------------')
    print(bin(1))
    print(bin(10000**1000))
    
    print('bool()---------')
    print(bool())
    print(bool(0))
    print(bool(1))
    print(bool(2))
    
    print('issubclass()---')
    class jo:
        pass
    class joo(jo):
        pass
    class jook:
        pass
    print(issubclass(joo,jo))
    print(issubclass(jook,jo))
    >>>> bytearray('heheda')
    Traceback (most recent call last):
      File "<pyshell#28>", line 1, in <module>
        bytearray('heheda')
    TypeError: string argument without an encoding
    >>> bytearray(heheda)
    Traceback (most recent call last):
      File "<pyshell#29>", line 1, in <module>
        bytearray(heheda)
    NameError: name 'heheda' is not defined
    >>> bytearray('heheda',''utf-8)
    SyntaxError: invalid syntax
    >>> bytearray('heheda','utf-8')
    bytearray(b'heheda')
    >>> bytearray('heheda','gb2312')
    bytearray(b'heheda')
    >>> bytearray('heheda','BIG5')
    bytearray(b'heheda')
    >>> bytearray('呵呵哒','BIG5')
    Traceback (most recent call last):
      File "<pyshell#34>", line 1, in <module>
        bytearray('呵呵哒','BIG5')
    UnicodeEncodeError: 'big5' codec can't encode character 'u54d2' in position 2: illegal multibyte sequence
    >>> bytearray('呵呵哒','gb2312')
    bytearray(b'xbaxc7xbaxc7xdfxd5')
    >>> bytearray('呵呵哒','utf-8')
    bytearray(b'xe5x91xb5xe5x91xb5xe5x93x92')
    >>> is
    SyntaxError: invalid syntax
    >>> isinstance(jojo,str)
    Traceback (most recent call last):
      File "<pyshell#38>", line 1, in <module>
        isinstance(jojo,str)
    NameError: name 'jojo' is not defined
    >>> isinstance('jojo',str)
    True
    >>> isinstance('jojo',unicode)
    Traceback (most recent call last):
      File "<pyshell#40>", line 1, in <module>
        isinstance('jojo',unicode)
    NameError: name 'unicode' is not defined
    >>> isinstance('jojo','utf-8')
    Traceback (most recent call last):
      File "<pyshell#41>", line 1, in <module>
        isinstance('jojo','utf-8')
    TypeError: isinstance() arg 2 must be a type or tuple of types
    >>> isinstance('jojo','utf-8')
    
  • 相关阅读:
    JS使用及技巧.
    文件上传
    闭包
    文件拖拽上传
    zTree简单使用
    call apply bind
    jquery中操作jQuery对象的eq和get的差别与用法--操作前台显示之利器
    Cocos2d-x 文件路径下文件的读写
    Linux程序设计学习笔记----多线程编程基础概念与基本操作
    不easy查找Bug
  • 原文地址:https://www.cnblogs.com/jpr-ok/p/9187955.html
Copyright © 2011-2022 走看看