Design and History FAQ — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Library and Extension FAQ

Python Module Index

3.16.0a0 Documentation

Python Frequently Asked Questions

Why are floating-point calculations so inaccurate?¶

and think it is a bug in Python. It’s not. This has little to do with Python, and much more to do with how the underlying platform handles floating-point numbers.

floating-point arithmetic

and think it is a bug in Python. It’s not. This has little to do with Python, and much more to do with how the underlying platform handles floating-point numbers.

Why must ‘self’ be used explicitly in method definitions and calls?¶

The idea was borrowed from Modula-3. It turns out to be very useful, for a variety of reasons.

Why is join() a string method instead of a list or tuple method?¶

Strings became much more like other standard types starting in Python 1.6, when methods were added which give the same functionality that has always been available using the functions of the string module. Most of these

How fast are exceptions?¶

A try/except block is extremely efficient if no exceptions are raised. Actually catching an exception is expensive. In versions of Python prior to 2.0 it was common to use this idiom:

Why isn’t there a switch or case statement in Python?¶

In general, structured switch statements execute one block of code when an expression has a particular value or set of values. Since Python 3.10 one can easily match literal values, or constants within a namespace, with

How does Python manage memory?¶

Other implementations (such as Jython or PyPy), however, can rely on a different mechanism such as a full-blown garbage collector. This difference can cause some subtle porting problems if your Python code depends on the

gc: Interface to the cycle-detecting garbage collector.

Other implementations (such as Jython or PyPy), however, can rely on a different mechanism such as a full-blown garbage collector. This difference can cause some subtle porting problems if your Python code depends on the

atexit: Register and execute cleanup functions.

If you want to force Python to delete certain things on deallocation use the atexit module to run a function that will force those deletions.

Why are there separate tuple and list data types?¶

Lists and tuples, while similar in many respects, are generally used in fundamentally different ways. Tuples can be thought of as being similar to Pascal records or C structs; they’re small collections of related data wh

Time complexity of operations on built-in types

CPython’s lists are really variable-length arrays, not Lisp-style linked lists. The implementation uses a contiguous array of references to other objects, and keeps a pointer to this array and the array’s length in a lis

abc: Abstract base classes according to :pep:`3119`.

An interface specification for a module as provided by languages such as C++ and Java describes the prototypes for the methods and functions of the module. Many feel that compile-time enforcement of interface specificati

collections.abc: Abstract base classes for containers

An interface specification for a module as provided by languages such as C++ and Java describes the prototypes for the methods and functions of the module. Many feel that compile-time enforcement of interface specificati

doctest: Test pieces of code within docstrings.

An interface specification for a module as provided by languages such as C++ and Java describes the prototypes for the methods and functions of the module. Many feel that compile-time enforcement of interface specificati

unittest: Unit testing framework for Python.

An interface specification for a module as provided by languages such as C++ and Java describes the prototypes for the methods and functions of the module. Many feel that compile-time enforcement of interface specificati

Why is there no goto?¶

In the 1970s people realized that unrestricted goto could lead to messy “spaghetti” code that was hard to understand and revise. In a high-level language, it is also unneeded as long as there are ways to branch (in Pytho

Why is there no goto?¶

In the 1970s people realized that unrestricted goto could lead to messy “spaghetti” code that was hard to understand and revise. In a high-level language, it is also unneeded as long as there are ways to branch (in Pytho

contextlib.closing(generator)

For technical reasons, a generator used directly as a context manager would not work correctly. When, as is most common, a generator is used as an iterator run to completion, no closing is needed. When it is, wrap it as