0% found this document useful (0 votes)
3 views2 pages

Complete Guide to Python Functions

The document provides a complete guide to Python built-in functions, including their definitions and examples of usage. Key functions covered include abs, all, any, bin, len, sum, max, and min. Additionally, it presents solved problems demonstrating the application of these functions in various scenarios.

Uploaded by

Tejaswini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Complete Guide to Python Functions

The document provides a complete guide to Python built-in functions, including their definitions and examples of usage. Key functions covered include abs, all, any, bin, len, sum, max, and min. Additionally, it presents solved problems demonstrating the application of these functions in various scenarios.

Uploaded by

Tejaswini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like