21/04/2023 2:11 pm
Topic starter
Notifications
Clear all
What is an example of using array?
0
What is an example of using array?
Answer
Add a comment
Add a comment
1 Answer
0
21/04/2023 2:26 pm
# Create an array of integers my_array = [1, 2, 3, 4, 5] # Print the array print(my_array) # Accessing array elements print(my_array[0]) # Output: 1 print(my_array[2]) # Output: 3 # Modifying array elements my_array[1] = 10 print(my_array) # Output: [1, 10, 3, 4, 5] # Looping through an array for element in my_array: print(element)
In this example, we create an array called my_array
which contains the integers 1, 2, 3, 4, and 5. We print the array, access individual elements using their index, modify an element in the array, and loop through the array using a for
loop. This is just one simple example of how arrays can be used in programming to store and manipulate collections of data.
Add a comment
Add a comment
Forum Information
- 14 Forums
- 1,837 Topics
- 5,053 Posts
- 0 Online
- 1,079 Members
Our newest member: Tyronenodub
Latest Post: loli
Forum Icons:
Forum contains no unread posts
Forum contains unread posts
Topic Icons:
Not Replied
Replied
Active
Hot
Sticky
Unapproved
Solved
Private
Closed