Data Types in Python Online Quiz 2021
Which statement is correct?
The list is mutable and Tuple is immutable. A mutable data type means that a python object of this type can be modified. An immutable object can’t. So, Option B is correct.
Suppose a list with name arr, contains 5 elements. You can get the 2nd element from the list using:
- arr[2]
- arr[-1]
- arr[1]
arr[0] will give first element while second element is given by arr[1] So, Option 4 is correct
How to get the last element of list in python? Suppose we have list with name arr, which contains 5 elements.
- arr[0]
- arr[5]
- arr[last]
- arr[-1]
The arr[-n] syntax gets the nth-to-last element. So arr[-1] gets the last element, arr[-2] gets the second to last, etc. So, Option 4 is correct.
How to copy one list to another in python?
- l1[] = l2[]
- l1[] = l2
- l1[] = l2[:]
- l1 = l2
Answer
Options 1 and 2 syntaxes are incorrect while 4 will point both names to the same list. Hence C is the best way to copy one list to another. So, Option C is correct.