Python’s design philosophy is “small core language” + “large standard library”, so when Python wants to add a new feature, it is more likely to think about whether to add it to the core language support or put it into the library as an extension. library is very large and contains many modules. To use a function, you must import the corresponding module in advance, otherwise the function is invalid. And built-in functions are part of the interpreter; they take effect as the interpreter is started. So the number of built-in functions must be strictly controlled, or the Python interpreter will become large and bloated. In general, only functions that are used frequently or are more tightly bound to the language itself will be promoted as built-in functions.
There are currently 79 built-in functions provided by Python.
abs() | delattr() | hash() | memoryview() | set() |
all() | dict() | help() | min() | setattr() |
any() | dir() | hex() | next() | slice() |
ascii() | divmod() | id() | object() | sorted() |
bin() | enumerate() | input() | oct() | staticmethod() |
bool() | eval() | int() | open() | str() |
breakpoint() | 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() |
The above content is sorted alphabetically, and in order to better understand and master this knowledge, a simple classification is made, and some of the more difficult ones are analyzed with emphasis.
Mathematical operations
- abs(): returns the absolute value
- divmod(): returns the quotient and remainder
- max(): returns the maximum value
- min(): return the minimum value
- pow(): power calculation
- round(): rounds the number
- sum(): summation
Type conversion
- bool(): returns the Bool value
- int(): return integer
- float(): return floating point number
- dict(): return dictionary
- list(): return list
- tuple(): return tuple
- set(): return set
- str(): return string
- complex(): return complex number
- bytearray(): return byte array
- bytes(): return immutable byte array
- memoryview(): create a new memoryview object based on the passed parameters
- ord(): return the integer corresponding to the Unicode character
- chr(): return the Unicode character corresponding to the integer
- bin(): convert an integer to a binary string
- oct(): convert an integer to an octal string
- hex(): convert the integer to a hexadecimal string
- frozenset(): create an immutable set based on the incoming arguments
- enumerate(): create an enumeration based on iterable objects
- range(): create a new range object based on the passed arguments
- iter(): create a new iterable object based on the passed arguments
- slice(): create a new slice object based on the passed arguments
- super(): creates a new proxy object with subclass and parent relationship based on the passed arguments
- object(): creates a new object object
enumerate()
super()
The super() function is used to provide access to the methods and properties of a parent or sibling class. super() returns an object representing the parent class.
Sequence Operations
- all(): determines if each element is True
- any(): Determine if there are elements of True
- filter(): use the specified method to filter the elements
- map(): use the specified method to function on each element of the incoming iterable object to generate a new iterable object
- next(): return the next element value in the iterable object
- reversed(): reverses the sequence to generate a new iterable object
- sorted(): sort the iterable object and return a new list
- zip(): aggregates the elements in the same position in each iterable passed in, returning a new tuple type iterator
filter()
map()
zip()
Object Operations
- help(): return the help information of the object
- dir(): returns a list of properties within the object or current scope
- id(): return the unique identifier of the object
- hash(): get the hash value of the object
- type(): type: return the type of the object
- len(): return the length of the object
- ascii(): return the object’s printable table string representation
- format(): formatting display value
dir()
|
|
format()
see Python String Formatting Tool
Reflex operation
__import__()
.- isinstance(): determines if the object is an instance of any class element in a class or type tuple
- issubclass(): determines if the class is a subclass of another class or an element of any class in the type tuple
- hasattr(): check if the object contains attributes
- getattr(): get the value of an attribute of an object
- setattr(): set the value of the object’s attribute
- delattr(): remove the object’s attributes
- callable(): check if the object can be called
Variable operations
- globals(): returns a dictionary of global variables and their values in the current scope
- locals(): returns a dictionary of local variables and their values in the current scope
- vars(): returns a dictionary of local variables and their values in the current scope, or a list of properties of the object
Interaction
- print(): print output to the standard output object
- input(): reads user input values
File Operations
- open(): opens the file with the specified pattern and encoding, returns the file read/write object
Compile and execute
- compile(): compile the string into code or AST object, so that it can be executed by exec statement or eval for evaluation
- eval(): execute dynamic expressions to evaluate
- exec(): execute dynamic statement block
- repr(): return a string representation of an object (to the interpreter)
Decorator
- @property: Decorator that marks properties
- @classmethod: Decorator that marks methods as class methods
- @staticmethod: decorator that marks methods as static methods
Other Functions
- breakpoint()