a开头的库

import abc
'''
返回一个数的绝对值。 
参数可以是整数、浮点数或任何实现了 __abs__() 的对象。 
如果参数是一个复数,则返回它的模。
'''
a = 9.9
print(dir(abc))
print(type(dir(abc)))
abc_def_nums = len(dir(abc))
print('abc模块的方法有{}种'.format(abc_def_nums)) # abc模块的方法有16种

print('-'*10,"分割线","-"*10)
# 自定义all()函数
# 如果 iterable 的所有元素为真(或迭代器为空),返回 True 
def all(iterable):
    '''
    判断传入的变量是否可以迭代吧
    '''
    for element in iterable:
        if not element:
            return False
    return True
a = [1,2,0,4,5]
print(all(a))
print('-'*10,"分割线","-"*10)

def any(iterable):
    '''
    如果 iterable 的任一元素为真则返回 True。 
    如果迭代器为空,返回 False
    '''
    for element in iterable:
        if element:
            return True
    return False
print(any(a))
print('-'*10,"分割线","-"*10)


'''
ascii() 函数类似 repr() 函数, 返回一个表示对象的字符串, 
但是对于字符串中的非 ASCII 字符则返回通过 repr() 函数使用 \x, \u 或 \U 编码的字符。 
生成字符串类似 Python2 版本中 repr() 函数的返回值。
'''
# SyntaxError: (unicode error) 
# 'unicodeescape' codec can't decode bytes in position 428-429: truncated \xXX escape
print(ascii('111')) 
posted @ 2021-09-11 19:44  索匣  阅读(53)  评论(0编辑  收藏  举报