Computer Science
List AL is defined as follows : AL = [1, 2, 3, 4, 5]
Which of the following statements removes the middle element 3 from it so that the list AL equals [1, 2, 4, 5] ?
- del AL[2]
- AL[2:3] = []
- AL[2:2] = []
- AL[2] = []
- AL.remove(3)
Answer
del AL[2]
AL[2:3] = []
AL.remove(3)
Reason — del AL[2]
— The del
keyword deletes the element from the list AL
from index 2.AL[2:3]
= [] — The slicing of the list AL[2:3]
begins at index 2 and ends at index 2. Therefore, the element at index 2 will be replaced by an empty list [].AL.remove(3)
— The remove()
function removes an element from the list AL
from index 3."
Related Questions
To store values in terms of key and value, what core data type does Python provide ?
- list
- tuple
- class
- dictionary
What is the value of the following expression ?
3 + 3.00, 3**3.0- (6.0, 27.0)
- (6.0, 9.00)
- (6, 27)
- [6.0, 27.0]
- [6, 27]
Which two lines of code are valid strings in Python ?
- This is a string
- 'This is a string'
- (This is a string)
- "This is a string"
You have the following code segment :
String1 = "my" String2 = "work" print(String1 + String2)
What is the output of this code?
- my work
- work
- mywork
- my