Lists in Python
Lists are a collection of items in Python. Here's an example:
python
fruits = ["apple", "banana", "cherry"]
print(fruits)
In this example, fruits is a list of three items: "apple", "banana", and "cherry". We can access individual items in the list using their index value:
python
print(fruits[1])
This will print "banana", since it's the second item in the list (remember, indexing starts at 0).
We can also add items to a list using the append() method:
python
fruits.append("orange")
print(fruits)
This will add "orange" to the end of the list.
No comments:
Post a Comment