0
0
DSA Pythonprogramming~10 mins

Array Declaration and Initialization in DSA Python - Build from Scratch

Choose your learning style9 modes available
Array Declaration and Initialization
📖 Scenario: You are organizing a small fruit basket for a picnic. You want to keep track of the fruits you have by listing them in order.
🎯 Goal: Create an array (list) of fruits, add a new fruit count, and then display the list of fruits.
📋 What You'll Learn
Create a list called fruits with the exact elements: 'apple', 'banana', 'cherry'
Create a variable called new_fruit and set it to the string 'orange'
Add the new_fruit to the fruits list using the append method
Print the fruits list to show all fruits
💡 Why This Matters
🌍 Real World
Lists are used everywhere to keep track of collections like shopping items, tasks, or contacts.
💼 Career
Knowing how to create and update lists is a basic skill for programming jobs, especially in data handling and user interface development.
Progress0 / 4 steps
1
Create the initial array of fruits
Create a list called fruits with these exact elements in order: 'apple', 'banana', 'cherry'
DSA Python
Hint

Use square brackets [] to create a list and separate items with commas.

2
Add a new fruit variable
Create a variable called new_fruit and set it to the string 'orange'
DSA Python
Hint

Use the equals sign = to assign the string 'orange' to new_fruit.

3
Add the new fruit to the fruits list
Use the append method on the fruits list to add the new_fruit variable
DSA Python
Hint

Call fruits.append(new_fruit) to add the new fruit to the list.

4
Print the fruits list
Print the fruits list to display all the fruits after adding the new one
DSA Python
Hint

Use print(fruits) to show the list.