PYTHON HANDWRITTEN NOTES(Chapter 4: python collections):
Python(lists , tuples, sets, dictionary) handwritten notes |
Python collections provide powerful data structures to store and manipulate data efficiently, offering versatile options like lists, dictionaries, sets, and tuples, making Python a top choice for diverse data handling tasks.
One Shot/Quick Revision Of Python Collections:
In Python Collection is a Variable to store multiple values in a single variable. Python has FOUR types of collections:
1. LISTS (MORE)
2. TUPLES (MORE)
3. SETS (MORE)
4. DICTIONARY (MORE)
List:
- Lists are used to store multiple values of multiple datatypes in a single Variable.
- Python lists are ordered, mutable collections that can hold a variety of data types.
- To store the value in Lists we use Square Brackets([]).
BUILT-IN FUNCTIONS IN LISTS
Method | Description |
---|---|
append() | Adds an element at the end of the list. |
clear() | Removes all the elements from the list. |
copy() | Returns a copy of the list. |
count() | Returns the number of elements with the specified value. |
extend() | Add the elements of a list (or any iterable), to the end of the current list. |
index() | Returns the index of the first element with the specified value. |
insert() | Adds an element at the specified position. |
pop() | Removes the element at the specified position. |
remove() | Removes the item with the specified value. |
reverse() | Reverses the order of the list. |
sort() | Sorts the list. |
Tuples:
- Tuples are Similar To lists in many ways but have some different characteristics.
- Tuple is a collection that is Ordered and unchangeable.
- Tuples are written with Round Brackets.
BUILT-IN FUNCTION IN TUPLES
Method | Description |
---|---|
All() | Returns true if all element is true or if the tuple is empty. |
Any() | Return true if any element of the tuple is true. if the tuple is empty, return false |
Len() | Return the lent of the tuple. |
Enumerate() | Return Enumerate object of tuple. |
Max() | Return the maximum element of the elements given tuple. |
Min() | Return the minimum element of the given tuple. |
Sorted() | Input Element in tuple will sorted |
Sets:
- Sets are like tuples and set in many ways.
- A Set is a collection of values that are unordered, unchangeable, and also unindexed.
- Sets are written with curly brackets.
BUILT-IN FUNCTION IN SETS
Method | Description |
---|---|
add() | Adds an element to the set. |
clear() | Removes all the elements from the set. |
copy() | Return a copy of the set. |
difference() | Returns a set containing the difference between two or more sets. |
difference_update() | Removes the item in this set that is also. |
discard() | Remove the specified item. |
pop() | Removes the specified element. |
Dictionary:
- Dictionarys are used to store data as key: value pairs.
- A dictionary is a collection that is ordered, changeable, and does not allow duplicates.
- Dictionaries are written with curly brackets and have keys and values.
BUILT-IN FUNCTION IN DICTIONARY
Method | Description |
---|---|
clear() | Removes all the elements from the dictionary. |
copy() | Returns a copy of the dictionary. |
fromkeys() | Return a dictionary with the specified keys and values. |
get() | Returns the value of a specified key. |
keys() | Return a list containing the dictionary key. |
update() | Updates the directory with the specified key-value pairs. |
Values () | Returns a list of all the values in the dictionary. |
0 Comments