Lists are another type of object in Python. They are used to store an indexed list of items.
A list is created using square brackets with commas separating items.
The certain item in the list can be accessed by using its index in square brackets.
words = [“Hello”, “world”, “!”]
An empty list is created with an empty pair of square brackets.
empty_list = 
Typically, a list will contain items of a single item type, but it is also possible to include several different types.
Lists can also be nested within other lists.
number = 3
things = [“string”, 0, [1, 2, number], 4.56]
[1, 2, 3] 3
Indexing out of the bounds of possible list values causes an IndexError.
Some types, such as strings, can be indexed like lists. Indexing strings behaves as though you are indexing a list containing each character in the string.
For other types, such as integers, indexing them isn’t possible, and it causes a TypeError.
str = “Hello world!”
CLICK ON THE BUTTON BELOW TO GO TO THE PYTHON MAIN COURSE PAGE.
©️ License: All Rights Reserved
CONTACT HOLLA TECH – LEARN SUPPORT