📘 Python Crash Course – Chapter 3: Introducing Lists – Exercise 3-1 Solution
Welcome to another solution from Python Crash Course by Eric Matthes.
📝 Exercise 3-1
Task:Store the names of a few of your friends in a list called names.
Print each person’s name by accessing each element in the list, one at a time
✅ Solution Code:
name = ["jarvis" ,'friday' , 'hulk', 'natasha', 'captain']
print(name[0])
print(name[1])
print(name[2])
print(name[3])
print(name[4])
🧠 Code Explanation:
This Python code demonstrates how to store and access elements from a list. Here's how it works:
-
Create a list:
The variable
nameis assigned a list containing the names["jarvis", "friday", "hulk", "natasha", "captain"]. Each name is an element in the list. -
Access and print each element:
The
print()function is used to display each element of the list by accessing it using its index. The indices range from0to4, corresponding to the positions of the elements in the list.
🔍 Output:
jarvis
friday
hulk
natasha
captain
📚 Related Exercises from Chapter 3:
- ➤ Exercise 3-1 -> Names
- ➤ Exercise 3-2 -> Greetings
- ➤ Exercise 3-3 -> Your Own List
- ➤ Exercise 3-4 -> Guest List
- ➤ Exercise 3-5 -> Changing Guest List
- ➤ Exercise 3-6 -> More Guests
- ➤ Exercise 3-7 -> Shrinking Guest List
- ➤ Exercise 3-8 -> Seeing the World
- ➤ Exercise 3-9 -> Dinner Guests
- ➤ Exercise 3-10 -> Every Function
🔗 Connect With Us:
“The only way to learn a new programming language is by writing programs in it.”
– Dennis Ritchie
📌 Tags: #Python #PythonCrashCourse #CodingForBeginners #LearnPython #PythonProjects #PythonTips #introducingLists