Complete List of Python Built-in Functions and Their Explanations

 


List of Python Built-in Functions and Their Explanations

Python comes with many built-in functions that can be used directly without importing any modules. These functions help perform common tasks such as data type conversion, mathematical operations, iterations, and more.

Data Type Functions

Function Description
int() Converts to an integer
float() Converts to a floating-point number
str() Converts to a string
bool() Converts to a boolean (True/False)
list() Converts to a list
tuple() Converts to a tuple
set() Converts to a set (unique, unordered)
dict() Creates or converts to a dictionary
complex() Creates a complex number

Math Functions

Function Description
abs(x) Returns the absolute value
round(x, ndigits) Rounds to the specified number of digits
pow(x, y) Returns x raised to the power y
divmod(a, b) Returns a tuple (quotient, remainder)
sum(iterable) Returns the total of all elements
min() / max() Returns the minimum / maximum value

Iteration and Collection Functions

Function Description
range(start, stop, step) Generates a sequence of numbers
enumerate() Adds index to an iterable
zip() Combines multiple iterables
reversed() Reverses an iterable
sorted() Sorts elements
all() Returns True if all elements are true
any() Returns True if any element is true
len() Returns the number of items
map() Applies a function to each item in an iterable
filter() Filters items using a function
next() Gets the next item from an iterator

Text and Input Functions

Function Description
input() Takes user input from the console
print() Prints output to the console
format() Formats strings (also via f-strings)
chr(i) Converts integer to ASCII character
ord(c) Converts character to ASCII code

Type Checking and Introspection

Function Description
type() Returns the data type of an object
isinstance(obj, type) Checks if an object is an instance of a class/type
id() Returns the memory address of an object
hash() Returns the hash value (used in sets, dictionaries)

File and Code Execution Functions

Function Description
open(file, mode) Opens a file
exec() Executes Python code from a string
eval() Evaluates Python expressions from a string
compile() Compiles source code into a code object

Special and Utility Functions

Function Description
help() Displays the help/documentation
dir() Lists attributes/methods of an object
globals() / locals() Returns current global/local namespace
vars() Returns __dict__ of an object
callable() Checks if an object is callable
delattr(), getattr(), setattr() Attribute manipulation functions

Examples:

print(abs(-10))         # Output: 10
print(round(3.14159, 2))  # Output: 3.14
print(len([1, 2, 3]))    # Output: 3
print(sum([10, 20, 30])) # Output: 60
print(type("Hello"))     # Output: <class 'str'>

0 Comments:

Post a Comment