Python Built-in Functions - Complete Guide
abs(x)
Returns the absolute value of a number.
Example: abs(-10) → 10
all(iterable)
Returns True if all elements in the iterable are true.
Example: all([1, 2, 3]) → True; all([1, 0, 3]) → False
any(iterable)
Returns True if any element in the iterable is true.
Example: any([0, 0, 5]) → True
bin(x)
Converts an integer to a binary string.
Example: bin(10) → '0b1010'
len(obj)
Returns the length of an object.
Example: len('Python') → 6
sum(iterable)
Returns the sum of all elements in an iterable.
Example: sum([1, 2, 3]) → 6
max()
Returns the largest item.
Example: max([1, 5, 3]) → 5
min()
Returns the smallest item.
Example: min([1, 5, 3]) → 1
Solved Problems using Built-in Functions
Find squares of even numbers in a list
nums = [1,2,3,4,5,6] result = list(map(lambda x: x**2, filter(lambda x: x%2==0, nums))) print(result)
# Output: [4, 16, 36]
Find max word length in a sentence
sentence = 'Python built in functions are powerful' print(max([Link](), key=len)) # Output:
functions
Merge two lists into a dictionary
keys = ['a','b','c'] values = [1,2,3] print(dict(zip(keys, values))) # Output: {'a': 1, 'b': 2, 'c': 3}
Count vowels in a string
s = 'Tejaswini' vowels = 'aeiou' print(sum(1 for c in [Link]() if c in vowels)) # Output: 4