Lists:-
Lists are used to store multiple items in a single variable.
Lists are created using square brackets
List items are ordered, changeable, and allow duplicate values.
List items are indexed, the first item has index [0], the second item has index [1] etc.
Since lists are indexed, lists can have items with the same value
The list is changeable, meaning that we can change, add, and remove items in a list after it has been created.
List items are indexed and you can access them by referring to the index number
Negative indexing means start from the end
-1 refers to the last item, -2 refers to the second last item etc.
You can specify a range of indexes by specifying where to start and where to end the range.
When specifying a range, the return value will be a new list with the specified items.
To change the value of a specific item, refer to the index number
To insert a new list item, without replacing any of the existing values, we can use the insert() method.
The insert() method inserts an item at the specified index
Looping through a list:-
You can loop through the list items by using a for loop
You can also loop through the list items by referring to their index number.
Use the range() and len() functions to create a suitable iterable.
You can loop through the list items by using a while loop.
List Comprehensions:-
List comprehension offers a shorter syntax when you want to create a new list based on the values of an existing list.
Some list methods:-
append(), insert(),pop(),index(),remove(),count(),reverese(),sort()
Tuples:-
Tuples are used to store multiple items in a single variable.
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets.
Since they are unchangeable, there are not much operations that can be performed on tuples.
The operations that are allowed are same as that of lists.
Tuple Methods:- count(), index()
Sets:-
Sets are used to store multiple items in a single variable.
A set is a collection which is unordered, unchangeable*, and unindexed.
Sets are written with curly brackets.
* set items are unchangeable, but you can remove items and add new items.
Sets are unordered, so you cannot be sure in which order the items will appear.
Set Methods:-
Some mathematical operations that can be performed on sets(mathematics), can also be used on set datatype with proper name.
Dictionary:-
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered*, changeable and does not allow duplicates.
Dictionaries are written with curly brackets, and have keys and values
Dictionary items are ordered, changeable, and does not allow duplicates.
Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
Some default methods like,
clear(),
fromkeys(),
items(),
setdefault(), etc..