Exploring Python's Built-in Functions: A Curious Journey

Satisfy your curiosity with Python's built-in functions. Our guide takes you on an exploratory journey through Python's standard library, revealing the built-in wonders of the language.
E
Edtoks1:56 min read

How to list Built-ins like keywords, modules, packages, and exceptions with simple commands.

Keywords

You can print keyword with the following code

import keyword

reserved_keywords = keyword.kwlist
print(reserved_keywords)

Builtin Functions and Exceptions

You can print builtin functions with the following code

builtin_functions = dir(__builtins__)
#built_in_functions = dir(builtins)
print(builtin_functions)

or

builtin_functions = vars(__builtins__)
print(list(builtin_functions.keys()))

 

Refer to Built-in Exceptions to learn more

Print all the variables created in interactive mode with the simple command print(dir())

The below code prints the built-in modules and libraries

import pkgutil
import sysconfig

# Get the path to the standard library
std_lib_path = sysconfig.get_paths()['stdlib']

# Get a list of standard library modules by scanning the stdlib path
standard_library_modules = [name for _, name, _ in pkgutil.iter_modules([std_lib_path])]
print(standard_library_modules)

The below code print all the packages

import pkgutil

standard_library_modules = [name for _, name, _ in pkgutil.iter_modules()]
print(standard_library_modules)

 

Let's keep in touch!

Subscribe to keep up with latest updates. We promise not to spam you.