Here are some of the most commonly used Python functions across different categories:
1. Basic Built-in Functions
These are used frequently for general-purpose programming.
print() – Displays output.
len() – Returns the length of an object.
type() – Returns the type of an object.
id() – Returns the unique identifier of an object.
isinstance() – Checks if an object is an instance of a specific class.
input() – Takes user input as a string.
round() – Rounds a number to the given precision.
abs() – Returns the absolute value of a number.
2. Data Type Conversion Functions
These functions are used for type conversion.
int() – Converts to an integer.
float() – Converts to a float.
str() – Converts to a string.
list() – Converts to a list.
tuple() – Converts to a tuple.
dict() – Converts to a dictionary.
set() – Converts to a set.
3. String Functions
These are commonly used for string manipulation.
upper() – Converts a string to uppercase.
lower() – Converts a string to lowercase.
strip() – Removes leading and trailing spaces.
replace(old, new) – Replaces occurrences of a substring.
split(delimiter) – Splits a string into a list.
join(iterable) – Joins elements of an iterable into a string.
4. List and Tuple Functions
These help in handling sequences.
append() – Adds an item to the end of a list.
extend() – Extends a list by appending elements from another list.
insert(index, value) – Inserts a value at a specific index.
remove(value) – Removes the first occurrence of a value.
pop(index) – Removes and returns an element at the given index.
sort() – Sorts a list in ascending order.
reverse() – Reverses a list.
count(value) – Returns the count of a specific value in a list.
index(value) – Returns the index of the first occurrence of a value.
5. Dictionary Functions
Useful for handling key-value pairs.
keys() – Returns all keys in a dictionary.
values() – Returns all values in a dictionary.
items() – Returns key-value pairs as tuples.
get(key, default) – Returns the value of a key, or a default value if the key is missing.
update() – Updates the dictionary with another dictionary or key-value pairs.
pop(key) – Removes a key-value pair and returns the value.
6. Set Functions
Useful for handling unique elements.
add(value) – Adds a value to a set.
remove(value) – Removes a value from a set.
discard(value) – Removes a value if it exists (does not raise an error).
union(set2) – Returns the union of two sets.
intersection(set2) – Returns the intersection of two sets.
difference(set2) – Returns the difference between two sets.
7. Math Functions
These are useful for numerical operations.
max(iterable) – Returns the maximum value.
min(iterable) – Returns the minimum value.
sum(iterable) – Returns the sum of all elements.
pow(base, exp) – Returns base raised to the exponent.
math.sqrt(x) – Returns the square root of x.
math.floor(x) – Rounds down to the nearest integer.
math.ceil(x) – Rounds up to the nearest integer.
8. File Handling Functions
Used for working with files.
open(filename, mode) – Opens a file.
read() – Reads the content of a file.
write(content) – Writes content to a file.
readlines() – Reads all lines of a file into a list.
writelines(lines) – Writes a list of lines to a file.
close() – Closes the file.
9. Functional Programming Functions
Useful for higher-order functions.
map(function, iterable) – Applies a function to each item in an iterable.
filter(function, iterable) – Filters items in an iterable based on a condition.
reduce(function, iterable) – Reduces an iterable to a single value (requires functools).
lambda – Creates anonymous functions.
10. Exception Handling Functions
Used for handling errors.
try-except – Handles exceptions.
raise – Raises an exception manually.
assert – Used for debugging.
Would you like examples for any of these? 😊