What Is a List in Python?
What Is a List in Python? Author – Marie Codes There are different tools to use for Python, here is the downloaded Learn Python editor. Please see my brothers course, this is available for beginners and young coders and perfect for Learning Python for beginners. A list is an ordered collection of items.In Python, lists are created using square brackets [] and can store strings, numbers, or even other lists.For example, here’s a simple list of favorite foods: my_favorite_foods = [“tacos”, “pizza”, “pasta”] Here: my_favorite_foods is the variable name. Each item in the list is a string inside quotes. Items are separated by commas. You can print the list like this: print(my_favorite_foods) Output: [‘tacos’, ‘pizza’, ‘pasta’] Creating Multiple Lists Let’s create another list for desserts: my_favorite_desserts = [“ice cream”, “cake”, “cookies”] Again, you can print this list to see everything: print(my_favorite_desserts) Accessing Specific Items in a List Python uses zero-based indexing, meaning the first item has position 0. For example, in my_favorite_foods: tacos is index 0 pizza is index 1 pasta is index 2 To print just pasta, you use square brackets and the index: print(my_favorite_foods[2]) Output: pasta Combining Lists and Text in Print Statements You can make your output more human-readable by combining strings and list items: print(“My family is going to eat”, my_favorite_foods[2], “for dinner tonight.”) Output: My family is going to eat pasta for dinner tonight. Here’s another example mixing food and dessert: print(“After I eat”, my_favorite_foods[0], “I will have”, my_favorite_desserts[2] + “!”) Output: After I eat tacos I will have cookies! Notice how we use commas to separate parts of the sentence and + if we want to add punctuation directly to the word. Practice Challenge Try this on your own: Create a list called my_favorite_drinks with 3 drinks you love. Print the entire list. Print just the second drink in a sentence like: My favorite drink is ______. Example solution: my_favorite_drinks = [“lemonade”, “tea”, “smoothie”] print(my_favorite_drinks) print(“My favorite drink is”, my_favorite_drinks[1] + “.”) Conclusion Today you learned how to: Create lists in Python Access individual items by index Print items in sentences Practicing with lists is a fantastic way to get comfortable with Python basics. Keep experimenting—try adding more items, using different indexes, or combining lists in creative ways. Thanks for coding with me! If you enjoyed this tutorial, don’t forget to subscribe to our channel and share this post with friends who want to learn Python. Happy coding!
What Is a List in Python? Read More »

