Python3.6.x中内置函数总结及讲解
来源:
中文源码网 浏览:184 次 日期:2024-05-12 07:41:52
【下载文档: Python3.6.x中内置函数总结及讲解.txt 】
Python3.6.x中内置函数总结及讲解
Python3.6.x中内置函数总结
# -*- coding:utf-8 -*-
"""
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()
"""
from collections import Iterator,Iterable
# abs(x)
# 求绝对值
print(abs(-1),abs(1))
# all(iterable)
# 如果iterable的所有元素都为真,则返回True(iterable为空,返回True)
print(all([1,'a',[2]])) # True
print(all([0,'a',[]])) # False
print(all('')) # True
# any(iterable)
# 只要iterable中有一个元素为真,则返回True(iterable为空,返回False)
print(any([1,[],''])) # True
print(any([0,0.0,'',[],{},set()])) # False
print(any([])) # False
# ascii(s)
# 只在Python3中支持,用于在不支持Unicode的平台查看Unicode字符串
# 就像repr()那样,创建对象的可打印形式,但在结果中只是用ascii字符,非ascii字符都转换为合适的转义序列。
print(ascii('hello你好'))
# 'hello\u4f60\u597d'
# repr(obj)
# 将其它类型数据转换为字符串,支持大部分内置数据类型
print(repr(123)) # 123
print(repr('hello 你好')) # 'hello 你好'
print(repr([1,2,3])) # [1, 2, 3]
print(repr({'a':1})) # {'a': 1}
print(repr(object())) #