Some More Useful inbuilt Functions.
Last Updated: 02th September 2025
print()
- Prints the given object to the console.
- sep parameter is used to specify the separator between the objects.
- end parameter is used to specify the end character.
- file parameter is used to specify the file to write the output to.
print("Hello, World!")
print("Hello", "World!", sep=" - ")
print("Hello", "World!", end=" ")
print("Hello", "World!", file=open("output.txt", "w"))
input()
- Gets input from the user.
- prompt parameter is used to specify the prompt message.
- end parameter is used to specify the end character.
name = input("Enter your name: ", end=" ")
print("Hello", name)
eval()
- Evaluates the given string expression and returns the result.
- Not recommended for user input.
result = eval("10 + 40")
print(result) # 50
abs()
- Returns the absolute value of the given number.
print(abs(-10)) # 10
round()
- Returns the rounded value of the given number.
- ndigits parameter is used to specify the number of digits to round to.
print(round(3.14)) # 3
print(round(3.49)) # 3
print(round(3.51)) # 4
print(round(3.14, 2)) # 3.14
print(round(3.14159, 2)) # 3.14
all()
- Returns True if all elements of the given iterable are Truthy value.
print(all([True, True, True])) # True
print(all([True, False, True])) # False
print(all([1,,3,0])) # False
print(all([])) # True
any()
- Returns True if any element of the given iterable is Truthy value.
print(any([True, True, True])) # True
print(any([True, False, True])) # True
print(any([1,,3,0])) # True
print(any([])) # False
reversed()
- Returns a reversed iterator object.
- iterable parameter is used to specify the iterable to reverse.
print(list(reversed([1, 2, 3]))) # [3, 2, 1]
print(tuple(reversed((1, 2, 3)))) # (3, 2, 1)
print(set(reversed({1, 2, 3}))) # {3, 2, 1}
print(dict(reversed({"a": 1, "b": 2, "c": 3}))) # {'c': 3, 'b': 2, 'a': 1}
enumerate()
- Give the index of each element in the iterable.
- start parameter is used to specify the starting index.
print(list(enumerate([1, 2, 3]))) # [(0, 1), (1, 2), (2, 3)]
print(list(enumerate([1, 2, 3], start=1))) # [(1, 1), (2, 2), (3, 3)]
zip()
- Returns a zip object.
- Merges multiple iterables into a single iterator object.
print(list(zip([1, 2, 3], [4, 5, 6]))) # [(1, 4), (2, 5), (3, 6)]
names = ["A", "B", "C"]
scores = [90, 80, 70]
print(list(zip(names, scores)))
# Output: [('A', 90), ('B', 80), ('C', 70)]
max() & min()
- Returns the maximum or minimum value of the given iterable.
- key parameter is used to specify the key function.
print(max([1, 2, 3])) # 3
print(min([1, 2, 3])) # 1
words = ["python", "AI", "datascience"]
print(max(words, key=len)) # datascience
print(min(words, key=len)) # AI
sum()
- Returns the sum of the given iterable.
- start parameter is used to specify the starting value.
print(sum([1, 2, 3])) # 6
print(sum([1, 2, 3], start=10)) # 16
help()
- Displays the documentation for the given object.
help(print)
dir()
- Returns a list of the names of the attributes and methods of the given object.
print(dir([1, 2, 3])) # ['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
