Text of docs.python.org › 3.12 › library › functions.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Built-in Functions — Python 3.12.16 documentation

Navigation index modules | next | previous | Python » 3.12.16 Documentation » The Python Standard Library » Built-in Functions | Theme | 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 A abs() aiter() all() anext() any() ascii() B bin() bool() breakpoint() bytearray() bytes() C callable() chr() classmethod() compile() complex() D delattr() dict() dir() divmod() E enumerate() eval() exec() F filter() float() format() frozenset() G getattr() globals() H hasattr() hash() help() hex() I id() input() int() isinstance() issubclass() iter() L len() list() locals() M map() max() memoryview() min() N next() O object() oct() open() ord() P pow() print() property() R range() repr() reversed() round() S set() setattr() slice() sorted() staticmethod() str() sum() super() T tuple() type() V vars() Z zip() _ __import__() abs ( x ) ¶ 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 True if 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 next() builtin, and behaves similarly. This calls the __anext__() 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 StopAsyncIteration is raised. Added in version 3.10. any ( iterable ) ¶ Return True if any element of the iterable is true. If the iterable is empty, return False . 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 by repr() using \x , \u , or \U escapes.

This generates a string similar to that returned by repr() in Python 2. bin ( x ) ¶ Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() 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 format() for more information. class bool ( object = False , / ) ¶ Return a Boolean value, i.e. one of True or False .

The argument is converted using the standard truth testing procedure . If the argument is false or omitted, this returns False ; otherwise, it returns True . The bool class is a subclass of int (see Numeric Types — int, float, complex ). It cannot be subclassed further. Its only instances are False and True (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() , passing args and kws straight through. By default, sys.breakpointhook() calls pdb.set_trace() expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly import pdb or type as much code to enter the debugger. However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice.

If sys.breakpointhook() is not accessible, this function will raise RuntimeError . By default, the behavior of breakpoint() can be changed with the PYTHONBREAKPOINT environment variable. See sys.breakpointhook() for usage details. Note that this is not guaranteed if sys.breakpointhook() has been replaced. Raises an auditing event builtins.breakpoint with argument breakpointhook . Added in version 3.7. class bytearray ( source = b'' ) class bytearray ( source , encoding ) class bytearray ( source , encoding , errors ) Return a new array of bytes.

The bytearray class is a mutable sequence of integers in the range 0 <= x < 256. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types , as well as most methods that the bytes type has, see Bytes and Bytearray Operations . The optional source parameter can be used to initialize the array in a few different ways: If it is a string , you must also give the encoding (and optionally, errors ) parameters; bytearray() then converts the string to bytes using str.encode() .

If it is an integer , the array will have that size and will be initialized with null bytes. If it is an object conforming to the buffer interface , a read-only buffer of the object will be used to initialize the bytes array. If it is an iterable , it must be an iterable of integers in the range 0 <= x < 256 , which are used as the initial contents of the array. Without an argument, an array of size 0 is created. See also Binary Sequence Types — bytes, bytearray, memoryview and Bytearray Objects . class bytes ( source = b'' ) class bytes ( source , encoding ) class bytes ( source , encoding , errors ) Return a new “bytes” object which is an immutable sequence of integers in the range 0 <= x < 256 . bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior.

Accordingly, constructor arguments are interpreted as for bytearray() . Bytes objects can also be created with literals, see String and Bytes literals . See also Binary Sequence Types — bytes, bytearray, memoryview , Bytes Objects , and Bytes and Bytearray Operations . callable ( object ) ¶ Return True if the object argument appears callable, False if not. If this returns True , it is still possible that a call fails, but if it is False , calling object will never succeed.

Note that classes are callable (calling a class returns a new instance); instances are callable if their class has a __call__() method. Added in version 3.2: This function was first removed in Python 3.0 and then brought back in Python 3.2. chr ( i ) ¶ Return the string representing a character whose Unicode code point is the integer i . For example, chr(97) returns the string 'a' , while chr(8364) returns the string '€' .

This is the inverse of ord() . The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range. @ classmethod ¶ Transform a method into a class method. A class method receives the class as an implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom: class C : @classmethod def f ( cls , arg1 , arg2 ): ...

The @classmethod form is a function decorator – see Function definitions for details. A class method can be called either on the class (such as C.f() ) or on an instance (such as C().f() ). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument. Class methods are different than C++ or Java static methods. If you want those, see staticmethod() in this section.

For more information on class methods, see The standard type hierarchy . Changed

The rest of this page is on the live site.