Lists in Python

A list is just like an array i.e. an ordered sequence of items. Ordered sequence means items are ordered from 0 to n.

Items in list can be of different types i.e. not all items need to be of same data type. Declaring a list is just like declaring another variable in python. The only difference is how the values are assigned to it.

e.g. myList = [1, 2, “Three”, True]

First two elements are numbers, then it’s a string and the last one is of boolean type

Items in the list can also be lists i.e. lists can be nested. Items in nested lists are accessed with an additional index position specified in brackets

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s