This Python module provides direct access to all ‘built-in’ identifiers of Python. For example, builtins.open is the full name for the built-in function
open(). This module is not normally accessed explicitly by most applications, but can be useful in modules that provide objects with the same name as a built-in value, but in which the built-in of that name is also needed.
For example, in a module that wants to implement an
open() function that wraps the built-in open(), this module can be used directly:
But in cases where there is a function with the same name as the builtin functions these needs to be called explicitly:
def open(path): f = builtins.open(path, 'r')
Here the first open function is defined by the programmer and the second one is being imported from the builtins module.
One more interesting thing to keep in mind is that the compiler gives higher priority to user-defined versions of the predefined functions contained by the builtins module. So, if a program consists of a call to both types of programs, the user-defined program will be called. To call the predefined version builtins keyword should be used.
calling for pre-defined version of pow() from builtins module to calculate 2**3
inside user-defined function pow() to calculate 2**3
Contents of Builtins Module
This module is automatically loaded every time the interpreter starts, this is the reason why it is generally never called explicitly. The following are defined within builtins:
- The Object Class– base class for all python objects
- All Built-in Data-Type Class– all data types like numbers, string, list etc.
- Built-in Exception Classes– like BaseException class, etc.
- Built-in Functions– functions like open(), abs(), all(), etc.
- Built-in Constants– constants like False, True, etc.
Built-in Data Type Classes
- TRUTH VALUE TESTING- statements and conditions for checking the validity of the code.
- BOOLEAN OPERATIONS- and, or, not.
- COMPARISONS- =, ==, !=, is and is not.
- NUMERIC TYPES- int, float, complex and bitwise operations like and, or, exclusive or, shifts and inverse.
- ITERATOR TYPES- operations related to iteration of a container.
- SEQUENCE TYPES- list, tuple, range and operations on these.
- TEXT SEQUENCE TYPE- str and methods related with string mutation and display.
- BINARY SEQUENCE TYPE- bytes, bytearray and memoryview.
- SET TYPES- set and frozenset.
- MAPPING TYPES- dict.
- CONTEXT MANAGER TYPES- runtime context related matter.
- OTHERS – module, instances, null object,
Example: simple program to depict the application of builtin types
not found not found found not found
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Byte Objects vs String in Python
- File Objects in Python
- Timer Objects in Python
- Barrier Objects in Python
- Python | Counter Objects | elements()
- Mutable vs Immutable Objects in Python
- Python Tkinter | Moving objects using Canvas.move() method
- Reading Python File-Like Objects from C | Python
- Python | Unit Test Objects Patching | Set-1
- Python | Unit Test Objects Patching | Set-2
- Django Request and Response cycle - HttpRequest and HttpResponse Objects
- Python Classes and Objects
- Python objects
- Print objects of a class in Python
- Python: Difference between Lock and Rlock objects
- Flattening JSON objects in Python
- Track objects with Camshift using OpenCV
- Session Objects - Python requests
- Python del to delete objects
- Python - Edit objects inside tuple
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.