Python Programming - Arrays
Exercise : Arrays - General Questions
- Arrays - General Questions
1.
What will be the output of the following code snippet?
numbers = [1, 2, 3, 4, 5]
numbers[1] = 9
print(numbers)
Answer: Option
Explanation:
Lists in Python are mutable, so you can change the value of an element using indexing.
2.
What will be the output of the following code snippet?
numbers = [1, 2, 3, 4, 5]
sliced_numbers = numbers[1:4]
print(sliced_numbers)
Answer: Option
Explanation:
Slicing is used to extract a portion of a list. In this case, it extracts elements from index 1 to 3.
numbers = [1, 2, 3, 4, 5]
sliced_numbers = numbers[1:4]
print(sliced_numbers)
3.
What will be the output of the following code snippet?
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)
Answer: Option
Explanation:
The
remove() method is used to remove a specific element from the list.
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)
4.
In Python, which module is commonly used for array operations?
Answer: Option
Explanation:
The
numpy module is commonly used for efficient array operations in Python.
5.
How do you create an array in Python using the
array module?
Answer: Option
Explanation:
The
array module provides the array() function to create arrays in Python.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers