Python Quiz-6

Q1. In Python, which of the following is the super class of all created classes?

  1. Super class
  2. Object class
  3. Integer class
  4. Base class

Answer: 2
Explanation: Object class is the super class of all created classes.

Q2. What will be the output of following code:

  1. [1, 2] [1, 2, 3]
  2. [1, 2, 3] [1, 2]
  3. [1, 2, 3] [1, 2, 3]
  4. [1, 2] [1, 2]

Answer: 4
Explanation: pop(index) method remove the item of a list at specified index. If index is not specified it will remove the first element of the list. Also as x is assigned to variable y and both refer to the same object in the memory, value of x and y will be same.

Q3. What will be the output of following code:

  1. 2
  2. 1
  3. 4
  4. 3

Answer: 1
Explanation: del x[1] => x = {2: ‘b’, 3: ‘c’}
x[1] = 5 => x = {2: ‘b’, 3: ‘c’, 1: 5}
del x[2] => x = {3: ‘c’, 1: 5}

Q4. What will be the output of following code:

  1. x y
  2. 1 2
  3. x y
  4. 1 2

Answer: 3
Explanation: **kwargs are used as arbitrary keyword arguments. If we do not know how many keyword arguments that will be passed into our function then we can add two asterisk ** before the parameter name in the function definition.
Arbitrary Keyword Arguments (**kwargs) make the way for the function to receive the dictionary of arguments.

Q5. In Python, which of the following is a numeric data type?

  1. int
  2. float
  3. complex
  4. All of the above.

Answer: 4
Explanation: In Python language, there are three types of numeric data.
1. int (Example : 0, 2, -1, etc.)
2.float (Example : 0.0, 2.3, -1.5, etc.)
3.complex(Example : 0j, 2j, -1.5j, etc.)

Q6. What will be the output of following code:

  1. {1, 2, 3} {1, 2, 3, 4}
  2. {1, 2, 3, 4} None
  3. {1, 2, 3, 4} {1, 2, 3, 4}
  4. Error

Answer: 2
Explanation: add() method does not return any value, that’s why x2 will be None.

Q7. What will be the output of following code”

  1. False 5
  2. True 5
  3. False 3
  4. True 3

Answer: 4
Explanation: When you open a file using with keyword, the file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.

Q8. What is the difference between a global variable and a local variable?

  1. Global variable can be used inside a function only while local variable can be used both inside and outside the function.
  2. Local variable can be used inside a function only while global variable can be used both inside and outside the function.
  3. Both are same.
  4. Both are different name for same variables.

Answer: 2
Explanation: As stated, Local variable can be used inside a function only while global variable can be used both inside and outside the function.

Leave a Reply