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

Final_Python_Functions_Cheat_Sheet

This cheat sheet provides a comprehensive overview of built-in Python functions, including their usage and examples. It covers various categories such as string, list, tuple, set, dictionary, file handling, math, random, and OS module functions. Each function is briefly described with an example to illustrate its application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Final_Python_Functions_Cheat_Sheet

This cheat sheet provides a comprehensive overview of built-in Python functions, including their usage and examples. It covers various categories such as string, list, tuple, set, dictionary, file handling, math, random, and OS module functions. Each function is briefly described with an example to illustrate its application.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Final 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

### String Functions


- upper(), lower(), capitalize(), title(), strip(), replace(), split(), join()
- startswith(), endswith(), find(), count()

### List Functions


- append(), extend(), insert(), remove(), pop(), index(), count(), sort(), reverse(), copy(), clear()

### Tuple Functions


- count(), index()

### Set Functions


- add(), remove(), discard(), pop(), clear(), union(), intersection(), difference(),
symmetric_difference(), issubset(), issuperset()

### Dictionary Functions


- keys(), values(), items(), get(), update(), pop(), popitem(), clear(), copy(), setdefault()

### File Handling Functions


- open(), read(), write(), close(), readline(), readlines(), writelines()

### Math Functions (from math module)


- sqrt(), ceil(), floor(), factorial(), gcd(), log(), sin(), cos(), tan()

### Random Functions (from random module)


- random(), randint(), choice(), shuffle(), uniform()

### OS Module Functions


- getcwd(), chdir(), listdir(), mkdir(), rmdir(), remove()

You might also like