Python Programming Multiple Choice Question -
This section focuses on the "Data Types" of the Python programming. These Multiple Choice Questions (mcq) should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which statement is correct?
Explanation: 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.
2. Suppose a list with name arr, contains 5 elements. You can get the 2nd element from the list using:
Explanation: arr will give first element while second element is given by arr
3. How to get last element of list in python? Suppose we have list with name arr, contains 5 elements.
Explanation: 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.
4. How to copy one list to another in python?
Explanation: Option A and B syntex is incorrect while D will point both name to same list. Hence C is the best way to copy the one list to another.
5. Suppose a tuple arr contains 10 elements. How can you set the 5th element of the tuple to ‘Hello’?
Explanation: Tuples are immutable i.e the value cannot be changed.
6. What type of data is: arr = [(1,1),(2,2),(3,3)]?
Explanation: Variable arr has tuples enclosed in a list. Hence it is list of tuples.
7. Can tuple be used as dictionary key in python?
Explanation: A dictionary key must be immutable. You can use a tuple as a key if all of the elements contained in the tuple are immutable. If the tuple contains mutable objects, it cannot be used as a key. Hence a tuple to be used as a key can contain strings, numbers, and other tuples containing references to immutable objects.
8. What is the output of the following program : print((1, 2) + (3, 4))
Explanation: + operator concatenate tuples, it can be used to combine tuples to form a new tuple.
Also check :