w3resource

Python: Create an array of 5 integers and display the array items

Python: Array Exercise-1 with Solution

Write a Python program to create an array of 5 integers and display the array items. Access individual elements through indexes.

Pictorial Presentation:

Python Exercises: Create an array of 5 integers and display the array items

Sample Solution:

Python Code :

from array import *
array_num = array('i', [1,3,5,7,9])
for i in array_num:
    print(i)
print("Access first three items individually")
print(array_num[0])
print(array_num[1])
print(array_num[2])

Sample Output:

1                                                                      
3                                                                      
5                                                                      
7                                                                      
9                                                                      
Access first three items individually                                  
1                                                                      
3                                                                      
5

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Python Array Exercise Home.
Next: Write a Python program to append a new item to the end of the array.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/array/python-array-exercise-1.php