Article Directory
Scenes
It mainly records the related built-in functions and reserved words of Python.
surroundings
software | version |
---|---|
Python | 3 |
text
Built-in function
function | Paraphrase |
---|---|
abs(x) | Returns the absolute value of x (int, float) |
all(iteralbe) | If the elements in iteralbe are all True or iterable is empty, return True |
any(iterable) | If any element in iterable is True, return True, if iterable is empty, return False |
ascii(obj) | Return the repr() output of obj, which is represented by \x, \u or \U for non-printable characters |
am (x) | Convert an integer x to a binary string form, starting with 0b |
bytearray() | Return a new byte array |
bool([x]) | Used to convert the given parameter to boolean type, if there is no parameter, return False. bool is a subclass of int |
bytes(src) | Convert src into a new byte string type bool(x) |
classmethod() | Decorator function, which converts the method into a class object, corresponding to the syntactic sugar @classmethod |
compile(src,filename,mode) | Compile src into code or AST object |
callable(object) | Used to check whether an object is callable. If it returns True, the call to object may still fail; but if it returns False, the call to object will never succeed. __call__ It returns True for functions, methods, lambda functions, classes, and class instances that implement methods. |
chr(int) | Returns the character represented by int in unicode encoding |
complex(r[,i]) | Convert the input value/tuple/string into a (complex) object and return |
dict() | Return a new dictionary object |
divmod (inta, intb) | Return the result of (a//b, a%b) |
delattr(obj,name) | Delete the name attribute of the obj object |
dir (obj) | Return all legal attributes of obj |
enumerate(iterable) | Returns an enum object initialized by iterable (a sequence of two tuples consisting of serial number and value) |
exec(obj) | Execute the passed string or code object |
eval(exp) | Pass the string expression exp as a legal statement to Python for interpretation and execution |
float(x) | Convert numbers or strings to floating point numbers |
filter(func,iteralbe) | Pass the iterable object to the function fucn and construct the True object as an iterator |
format(value[,format_spec]) | Format the value according to the foramt_spec format |
frozenset([iterable]) | Return an unmodifiable collection object, which can be initialized with the iterable parameter |
getattr(obj,name) | Returns the name attribute of the obj object |
globals() | Return a dictionary composed of the current global variables |
hash(obj) | Returns the hash value of the object obj |
hex(int) | Convert int to hexadecimal and return the result of a string prefixed with 0x in all lowercase |
hasattr(obj,name) | If the obj object has a name attribute, it returns True, otherwise it returns False |
help(obj) | Returns the help document of the obj object |
isinstance(obj,classinfo) | If the object obj is an instance of classinfo, it returns True, otherwise it returns False |
issubclass(class, classinfo) | If the class class is a subclass of classinfo, return True, otherwise return False |
iter(obj) | Returns the iterator constructed by the obj object, obj must be an iterable object |
id() | Returns the id value of obj in Python, generally refers to the memory address of the object changed in CPython |
input([prompt]) | Display the string prompt on the screen and wait for input |
int(x) | Convert number/string x to integer |
len (s) | Returns the length of the object s |
list([iterable]) | Return a new list object, which can be initialized with the iterable parameter |
locals() | Return a dictionary composed of the current local variables |
map(func,iterable) | Returns the iterator constructed by passing each object in iterable to the function func |
memoryview(obj) | 返回obj对象的Memory View信息 |
max(iterable) | 返回iterable中最大值 |
min(iterable) | 返回iterable中最小值 |
next(iterator) | 返回迭代器中的下一个元素,会改变迭代器状态 |
object | 最基础的对象,它的类是所有类的基类 |
oct(int) | 将int转换为八进制,返回0o为前缀的字符串结果 |
open(file, mode) | 以mode方式打开文件并返回文件对象 |
ord© | 与chr()相反,返回字符c的unicode编码值 |
pow(x,y[,z]) | 返回x的y次方,可选参数z用于取模 |
print(x) | 打印 |
property() | 装饰器函数,用于将方法转换为属性,对应语法糖@property |
repr(obj) | 调用obj对象的repr()方法,返回目标对象的可打印字符串 |
reverse(seq) | 返回将序列seq反向后构造的迭代器 |
range(start, stop[,step]) | 从start开始到stop结束,以step为步进的序列 |
round(x) | 对x近似取整 |
set([iterable]) | 返回一个新的集合对象,可用iterable参数初始化 |
str(x) | 将x转换为字符串 |
setattr(obj,name,value) | 为obj对象增加name属性,属性值value |
slice(start, stop[,step]) | 返回start(包含)开始,stop(不包含)结束的可切片对象,可选参数step控制步进间隔 |
sorted(iterable) | 返回一个由iterable对象元素排序后构成的新列表对象 |
staticmethode() | 装饰器函数,将方法转换为静态方法,对应语法糖@staticmethod |
sum(iterable[, start]) | 对序列进行求和计算 |
super(type[, object-or-type]) | 是用于调用父类(超类)的一个方法。super() 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承,会涉及到查找顺序(MRO)、重复调用(钻石继承)等种种问题。MRO 就是类的方法解析顺序表, 其实也就是继承父类方法时的顺序表。 |
tuple( iterable ) | 将可迭代系列(如列表)转换为元组 |
type(object)/type(name, bases, dict) | 如果你只有第一个参数则返回对象的类型,三个参数返回新的类型对象 |
vars(obj) | 返回obj模块/类/对象的dict属性 |
zip(*iterable) | 从各iterable对象中提取元素拼成元组,形成并返回新的迭代器 |
__import__(name[, globals[, locals[, fromlist[, level]]]]) |
__import__() 函数用于动态加载类和函数 。如果一个模块经常变化就可以使用 __import__() 来动态载入。 |
注意
isinstance() 与 type() 区别:
type() 不会认为子类是一种父类类型,不考虑继承关系。
isinstance() 会认为子类是一种父类类型,考虑继承关系。
如果要判断两个类型是否相同推荐使用 isinstance()。
Python保留字
被编程语言内部定义并保留使用的的关键字
查询方式
import keyword
print(keyword.kwlist)
列表
扩展
总结
多思多想!!!
随缘求赞
如果我的文章对大家产生了帮忙,可以在文章底部点个赞或者收藏;
如果有好的讨论,可以留言;
如果想继续查看我以后的文章,可以点击关注
可以扫描以下二维码,关注我的公众号:枫夜之求索阁,查看我最新的分享!