What is a list in Python?
A list is an ordered, changeable collection of items written inside square brackets [ ]. A list can hold items of different types and it allows duplicate values.
fruits = ["apple", "banana", "cherry"]
fruits.append("mango")
print(fruits)
print(fruits[0])
print(len(fruits))
Output:
Tutorials Class - Output Window
['apple', 'banana', 'cherry', 'mango']
apple
4
Items are numbered from 0, so fruits[0] is the first item. Because a list is mutable, you can add, remove or change items after creating it. Learn more in the Python Lists chapter.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |