Exercise: Arrays
Questions for: Arrays
In Python, which module is commonly used for array operations?
A:
list
B:
array
C:
numpy
D:
math
Answer: C
The
numpy module is commonly used for efficient array operations in Python.
What will be the output of the following code snippet?
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)
A:
['apple', 'banana', 'cherry']
B:
['apple', 'cherry']
C:
['banana', 'cherry']
D:
Error
Answer: B
The
remove() method is used to remove a specific element from the list.
fruits = ['apple', 'banana', 'cherry']
fruits.remove('banana')
print(fruits)
Discuss About this Question.
What will be the output of the following code snippet?
numbers = [1, 2, 3, 4, 5]
sliced_numbers = numbers[1:4]
print(sliced_numbers)
A:
[1, 2, 3, 4, 5]
B:
[2, 3, 4]
C:
[1, 2, 3]
D:
[3, 4, 5]
Answer: B
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)
Discuss About this Question.
What will be the output of the following code snippet?
numbers = [1, 2, 3, 4, 5]
numbers[1] = 9
print(numbers)
A:
[1, 9, 3, 4, 5]
B:
[1, 2, 3, 4, 5]
C:
[9, 2, 3, 4, 5]
D:
Error
Answer: A
Lists in Python are mutable, so you can change the value of an element using indexing.
Discuss About this Question.
What will be the output of the C#.NET code snippet given below?
namespace ExamAdept
{
class SampleProgram
{
static void Main(string[ ] args)
{
int i, j;
int[ , ] arr = new int[ 2, 2 ];
for(i = 0; i < 2; ++i)
{
for(j = 0; j < 2; ++j)
{
arr[i, j] = i * 17 + i * 17;
Console.Write(arr[ i, j ] + " ");
}
}
}
}
}
A:
0 0 34 34
B:
0 0 17 17
C:
0 0 0 0
D:
17 17 0 0
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.