Built-in Functions¶
The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.
Built-in Functions |
|||
|---|---|---|---|
- abs(number, /)¶
Return the absolute value of a number. The argument may be an integer, a floating-point number, or an object implementing
__abs__(). If the argument is a complex number, its magnitude is returned.
- aiter(async_iterable, /)¶
Return an asynchronous iterator for an asynchronous iterable. Equivalent to calling
x.__aiter__().Note: Unlike
iter(),aiter()has no 2-argument variant.Added in version 3.10.
- all(iterable, /)¶
Return
Trueif all elements of the iterable are true (or if the iterable is empty). Equivalent to:def all(iterable): for element in iterable: if not element: return False return True
- awaitable anext(async_iterator, /)
- awaitable anext(async_iterator, default, /)
When awaited, return the next item from the given asynchronous iterator, or default if given and the iterator is exhausted.
This is the async variant of the builtin, and behaves similarly.
This calls the method of async_iterator, returning an awaitable. Awaiting this returns the next value of the iterator. If default is given, it is returned if the iterator is exhausted, otherwise
StopAsyncIterationis raised.Added in version 3.10.
- any(iterable, /)¶
Return
Trueif any element of the iterable is true. If the iterable is empty, returnFalse. Equivalent to:def any(iterable): for element in iterable: if element: return True return False
- ascii(object, /)¶
As
repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned byrepr()using\x,\u, or\Uescapes. This generates a string similar to that returned byrepr()in Python 2.
- bin(integer, /)¶
Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If integer is not a Python
intobject, it has to define an method that returns an integer. Some examples:>>> bin(3) '0b11' >>> bin(-10) '-0b1010'
If the prefix “0b” is desired or not, you can use either of the following ways.
>>> format(14, '#b'), format(14, 'b') ('0b1110', '1110') >>> f'{14:#b}', f'{14:b}' ('0b1110', '1110')
See also
enum.bin()to represent negative values as twos-complement.See also
format()for more information.
- class bool(object=False, /)¶
Return a Boolean value, i.e. one of
TrueorFalse. The argument is converted using the standard truth testing procedure. If the argument is false or omitted, this returnsFalse; otherwise, it returnsTrue. Theboolclass is a subclass ofint(see Numeric Types — int, float, complex). It cannot be subclassed further. Its only instances areFalseandTrue(see Boolean Type - bool).Changed in version 3.7: The parameter is now positional-only.
- breakpoint(*args, **kws)¶
This function drops you into the debugger at the call site. Specifically, it calls
sys.breakpointhook(), passingargsandkwsstraight through. By default,sys.breakpointhook()callspdb.set_trace()expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly importpdbor type as much code to enter the debugger. However,sys.breakpointhook()can be set to some other function andbreakpoint()will automatically call that, allowing you to drop into the debugger of choice. Ifsys.breakpointhook()is not accessible, this function will raiseRuntimeError.By default, the behavior of
breakpoint()can be changed with thePYTHONBREAKPOINTenvironment variable. Seesys.breakpointhook()for usage details.Note that this is not guaranteed if
sys.breakpointhook()has been replaced.Raises an auditing event
builtins.breakpointwith argumentbreakpointhook.
评论
0 条评论
请登录写评论。