Comprehensive Guide to Python's 66 Built‑in Functions
This article presents a detailed overview of Python's 66 built‑in functions, explaining each function's purpose and providing concise example code to illustrate typical usage across numeric, sequence, conversion, and introspection operations.
Python includes 66 built‑in functions that are always available without importing any modules, covering common tasks such as numeric operations, sequence handling, type conversion, and object introspection.
1. abs(x) : Returns the absolute value of a number.
<code>x = -10
print(abs(x)) # 输出:10</code>2. all(iterable) : Returns True if all elements of the iterable are true.
<code>iterable = [True, True, False]
print(all(iterable)) # 输出:False</code>3. any(iterable) : Returns True if any element of the iterable is true.
<code>iterable = [False, False, True]
print(any(iterable)) # 输出:True</code>4. bin(x) : Converts an integer to its binary string representation.
<code>x = 10
print(bin(x)) # 输出:0b1010</code>5. bool(x) : Converts a value to a Boolean.
<code>x = 0
print(bool(x)) # 输出:False</code>6. bytearray([source[, encoding[, errors]]]) : Creates a mutable byte array.
<code>source = b'Hello'
arr = bytearray(source)
print(arr) # 输出:bytearray(b'Hello')</code>7. bytes([source[, encoding[, errors]]]) : Creates an immutable bytes object.
<code>source = 'Hello'
b = bytes(source, encoding='utf-8')
print(b) # 输出:b'Hello'</code>8. callable(object) : Checks whether an object appears callable (e.g., a function or method).
<code>def func():
pass
print(callable(func)) # 输出:True</code>9. chr(i) : Returns the character whose Unicode code point is the integer i .
<code>i = 65
print(chr(i)) # 输出:A</code>10. classmethod(func) : Converts a regular method into a class method.
<code>class MyClass:
attr = 10
@classmethod
def class_method(cls):
print(cls.attr)
MyClass.class_method() # 输出:10</code>... (functions 11 through 66 are presented in the same format, each with a brief description and a short code example illustrating its behavior, such as compile , complex , delattr , dict , dir , divmod , enumerate , eval , exec , filter , float , format , frozenset , getattr , globals , hasattr , hash , help , hex , id , input , int , isinstance , issubclass , iter , len , list , locals , map , max , memoryview , min , next , object , oct , open , ord , pow , print , property , range , repr , reversed , round , set , setattr , slice , sorted , staticmethod , str , sum , super , tuple , type , vars , and zip ).
At the end of the article, a QR code is provided for readers to claim a free Python public course and a collection of learning resources, including e‑books, tutorials, project templates, and source code.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.