w3resource logo
Python Exercises

Python: Array Exercises, Practice, Solution

Python Array [13 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

Python array module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained.

1. Write a Python program to create an array of 5 integers and display the array items. Access individual element through indexes. Go to the editor
Click me to see the sample solution

2. Write a Python program to append a new item to the end of the array. Go to the editor
Click me to see the sample solution

3. Write a Python program to reverse the order of the items in the array. Go to the editor
Click me to see the sample solution

4. Write a Python program to get the length in bytes of one array item in the internal representation. Go to the editor
Click me to see the sample solution

5. Write a Python program to get the current memory address and the length in elements of the buffer used to hold an array?s contents and also find the size of the memory buffer in bytes. Go to the editor
Click me to see the sample solution

6. Write a Python program to get the number of occurrences of a specified element in an array. Go to the editor
Click me to see the sample solution

7. Write a Python program to append items from inerrable to the end of the array. Go to the editor
Click me to see the sample solution

8. Write a Python program to convert an array to an array of machine values and return the bytes representation. Go to the editor
Click me to see the sample solution

9. Write a Python program to append items from a specified list. Go to the editor
Click me to see the sample solution

10. Write a Python program to insert a new item before the second element in an existing array. Go to the editor
Click me to see the sample solution

11. Write a Python program to remove a specified item using the index from an array. Go to the editor
Click me to see the sample solution

12. Write a Python program to remove the first occurrence of a specified element from an array. Go to the editor
Click me to see the sample solution

13. Write a Python program to convert an array to an ordinary list with the same items. Go to the editor
Click me to see the sample solution

Python Code Editor: