Python (Scripting) - Getting Started with Lists

by
Jeremy Canfield |
Updated: November 18 2024
| Python (Scripting) articles
This is an empty list that contains no values.
fruits = []
This is an list that contains values.
fruits = ["apple", "banana", "orange", "grapes"]
You can print the list. This will display the entire list.
print(fruits)
Which should return the following.
['apple', 'banana', 'orange', 'grapes']
You can print a certain value in the list. This will print "apple".
print(fruits[0])
You can loop through the list.
for x in fruits:
print(x)
This will print each fruit.
apple
banana
orange
grapes
join can be used to convert the list to a string if you want to print the list in a simple one liner.
fruits = ["apple", "banana", "orange", "grapes"]
print(' '.join([x for x in fruits]))
Did you find this article helpful?
If so, consider buying me a coffee over at