1. What is a Python array?
Answer:
Explanation:
A Python array is a linear data structure for storing elements of the same data type.
2. How are elements accessed in a Python array?
Answer:
Explanation:
Elements in a Python array are accessed using an index.
3. Which module is commonly used for working with Python arrays?
Answer:
Explanation:
The `array` module is commonly used for working with Python arrays.
4. What is the purpose of the append() method in Python arrays?
Answer:
Explanation:
The `append()` method is used to add an element to the end of a Python array.
5. How can you remove an element from a Python array by its value?
Answer:
Explanation:
The `remove()` method is used to remove an element from a Python array by its value.
6. What is the purpose of the pop() method in Python arrays?
Answer:
Explanation:
The `pop()` method removes and returns the last element of a Python array.
7. Which method is used to check if an element exists in a Python array?
Answer:
Explanation:
You can check if an element exists in a Python array using the `in` keyword.
8. Which method is used to sort a Python array in ascending order?
Answer:
Explanation:
The `sort()` method is used to sort a Python array in ascending order.
9. How can you reverse the order of elements in a Python array?
Answer:
Explanation:
The `reverse()` method is used to reverse the order of elements in a Python array.
10. Which method is used to clear all elements from a Python array?
Answer:
Explanation:
The `clear()` method is used to clear all elements from a Python array.
11. What is the time complexity of accessing an element in a Python array by index?
Answer:
Explanation:
Accessing an element in a Python array by index has a time complexity of O(1).
12. Which data structure is used to implement Python arrays?
Answer:
Explanation:
Python arrays are implemented as dynamic arrays.
13. What is the primary purpose of using arrays in Python?
Answer:
Explanation:
The primary purpose of using arrays in Python is to store and manipulate a collection of elements efficiently.
14. Which module provides support for numerical arrays and mathematical operations in Python?
Answer:
Explanation:
The `numpy` module provides support for numerical arrays and mathematical operations in Python.
15. What is the result of using the extend() method to add elements from one array to another?
Answer:
Explanation:
The `extend()` method modifies the original array to include elements from the second array.
16. Which method is used to insert an element at a specific index in a Python array?
Answer:
Explanation:
The `insert()` method is used to insert an element at a specific index in a Python array.
17. How can you find the index of the first occurrence of an element in a Python array?
Answer:
Explanation:
The `index()` method is used to find the index of the first occurrence of an element in a Python array.
18. Which method is used to count the number of occurrences of an element in a Python array?
Answer:
Explanation:
The `count()` method is used to count the number of occurrences of an element in a Python array.
19. What is the result of using the copy() method to create a copy of a Python array?
Answer:
Explanation:
The `copy()` method creates a shallow copy of the original array.
20. Which method is used to remove the element at a specific index in a Python array?
Answer:
Explanation:
The `pop()` method is used to remove the element at a specific index in a Python array.