The if and else blocks will remain the same. The elif statement comes in between the two.
svg viewer
Let’s write an if-elif-else statement which checks the state of a traffic signal and generates the appropriate response:
The list is perhaps the most commonly used data structure in Python. It allows us to store elements of different data types in one container.
The contents of a list are enclosed by square brackets, [].
Lists are ordered, like strings. Elements are stored linearly at a specific index.
svg viewer
We can see from the illustration above that a list bears resemblance to a string.
A string is a collection of characters indexed in a linear fashion. A list is the same except that it can contain any type of data, even another list!
Creating a List
Let’s see how to create a list using square brackets.