28 Aug admin
Python Collections (Arrays)
There are four collection data types in the Python programming language:
- List is a collection which is ordered and changeable. Allows duplicate members.
- Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
- Set is a collection which is unordered and unindexed. No duplicate members.
- Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
List
A list is a collection which is ordered and changeable. In Python lists are written with square brackets.
alist = [“america”, “india”, “japan”]
print(alist)
Output-
['america', 'india', 'japan']
Access Items
You access the list items by referring to the index number:
alist = [“apple”, “banana”, “cherry”]
print(alist[2])
output:-cherry