Day 2 of #10dayofpythondatatypes – Python List

The list is one of the most widely used data types in Python. And it’s formed(or created) by placing all the items (elements) inside square brackets [ ], separated by commas.

It can have any number of items and they may or may not be of different types (integer, float, string, etc.).

A list is MUTABLE, which suggests we can modify the list after it’s been created unlike tuple. We will learn more on Tuple by Tommorrow.

Example:

List1 = [3, 8, 7.2, “Hello”, {‘Happy’: 1, ‘New’: 2, ‘Year’: ‘3’} ]
print(“List1[2] = “, List[2])
Output: List1[2] = 7.2
print(“List1[1:3] = “, List[1:3])
Output: List1[1:3] = [8, 7.2]

PS: There is a usage of slicing in the print function applied above. A topic for another day.

Leave a Comment