What is an example …
 
Notifications
Clear all

What is an example of using array?

1 Posts
2 Users
0 Likes
323 Views
0
Topic starter

What is an example of using array?

1 Answer
0
# 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.

Share: