Lists and arrays are important tools in programming. They let you keep track of groups of items. You can do many things with them. Let’s look at some of the basic actions you can take!
Creating a list or an array is easy.
fruits = ["apple", "banana", "orange"]
numbers = [1, 2, 3, 4, 5]
You can get items from your list or array using their position, called an index. The count starts at 0.
fruits[0]
, which gives you "apple"
.You can add new items to your list or array.
append()
, like this: fruits.append("grape")
.It’s easy to remove items too.
remove()
, like this: fruits.remove("banana")
.Sorting helps to put your items in order.
fruits.sort()
sorts the list from A to Z.You can look at each item one by one using a for
loop.
for fruit in fruits:
print(fruit)
These actions make lists and arrays great for handling data in programming!
Lists and arrays are important tools in programming. They let you keep track of groups of items. You can do many things with them. Let’s look at some of the basic actions you can take!
Creating a list or an array is easy.
fruits = ["apple", "banana", "orange"]
numbers = [1, 2, 3, 4, 5]
You can get items from your list or array using their position, called an index. The count starts at 0.
fruits[0]
, which gives you "apple"
.You can add new items to your list or array.
append()
, like this: fruits.append("grape")
.It’s easy to remove items too.
remove()
, like this: fruits.remove("banana")
.Sorting helps to put your items in order.
fruits.sort()
sorts the list from A to Z.You can look at each item one by one using a for
loop.
for fruit in fruits:
print(fruit)
These actions make lists and arrays great for handling data in programming!