0% found this document useful (0 votes)
12 views

Complete Python Functions Cheat Sheet

This document is a comprehensive cheat sheet for Python built-in functions, providing a list of functions along with their descriptions and examples. Key functions include print(), input(), len(), and type(), among others, each demonstrating their usage with code snippets. The document serves as a quick reference for Python developers to utilize these functions effectively.
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)
12 views

Complete Python Functions Cheat Sheet

This document is a comprehensive cheat sheet for Python built-in functions, providing a list of functions along with their descriptions and examples. Key functions include print(), input(), len(), and type(), among others, each demonstrating their usage with code snippets. The document serves as a quick reference for Python developers to utilize these functions effectively.
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
You are on page 1/ 2

Complete Python Functions Cheat Sheet

### Built-in Functions


1. print() - Displays output on the screen.
Example: print("Hello, World!") -> Hello, World!

2. input() - Takes user input as a string.


Example: name = input("Enter your name: ")

3. len() - Returns the length of an object.


Example: len("Python") -> 6

4. type() - Returns the type of a variable.


Example: type(5.0) -> <class 'float'>

5. id() - Returns the memory address of an object.


Example: id(10)

6. isinstance() - Checks if an object is an instance of a specific class.


Example: isinstance(5, int) -> True

7. range() - Generates a sequence of numbers.


Example: list(range(1, 5)) -> [1, 2, 3, 4]

8. abs() - Returns the absolute value of a number.


Example: abs(-10) -> 10

9. round() - Rounds a number to a specified decimal places.


Example: round(3.456, 2) -> 3.46

10. pow() - Returns x raised to the power y.


Example: pow(2, 3) -> 8

11. sum() - Returns the sum of all elements in an iterable.


Example: sum([1, 2, 3]) -> 6
12. min() - Returns the smallest element in an iterable.
Example: min([4, 2, 8]) -> 2

13. max() - Returns the largest element in an iterable.


Example: max([4, 2, 8]) -> 8

14. sorted() - Returns a sorted list.


Example: sorted([3, 1, 2]) -> [1, 2, 3]

15. reversed() - Returns a reversed iterator.


Example: list(reversed([1, 2, 3])) -> [3, 2, 1]

16. enumerate() - Returns an index-value pair iterator.


Example: list(enumerate(['a', 'b'])) -> [(0, 'a'), (1, 'b')]

17. zip() - Combines multiple iterables into tuples.


Example: list(zip([1, 2], ['a', 'b'])) -> [(1, 'a'), (2, 'b')]

18. map() - Applies a function to all items in an iterable.


Example: list(map(str.upper, ["hello", "world"])) -> ['HELLO', 'WORLD']

19. filter() - Filters elements using a function.


Example: list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4])) -> [2, 4]

20. lambda - Creates anonymous functions.


Example: f = lambda x: x * 2; f(5) -> 10

... (Other functions continue in the same detailed format)

You might also like