Python Certification Exam Preparation Set 57

What will be the output of the following Python code?


Options are :

  • Error, copying of sets isn't allowed
  • {1,2,3} (Correct)
  • Error, invalid syntax for add
  • {1,2,3,4}

Answer :{1,2,3}

Python Certification Exam Preparation Set 16

What will be the output of the following Python code?


Options are :

  • 9997
  • 9996 (Correct)
  • None
  • 9999

Answer :9996

What will be the output of the following Python code snippet?


Options are :

  • None
  • Error
  • True
  • False (Correct)

Answer :False

What is the output of the following piece of code?


Options are :

  • 60
  • 15
  • An exception is thrown
  • 30 (Correct)

Answer :30

Python Certification Exam Preparation Set 3

What is the output of the code shown below?


Options are :

  • ValeError
  • TypeError
  • NameError (Correct)
  • IndexError

Answer :NameError

Which function overloads the + operator?


Options are :

  • __sum__()
  • none of the mentioned
  • __add__() (Correct)
  • __plus__()

Answer :__add__()

Overriding means changing behaviour of methods of derived class methods in the base class. Is the statement true or false?


Options are :

  • False (Correct)
  • True

Answer :False

Python Certification Exam Preparation Set 44

What happens if the file is not found in the code shown below?


Options are :

  • Assertion error
  • Name error
  • No error (Correct)
  • Input output error

Answer :No error

What is the output of the following code?


Options are :

  • The program runs fine and 8.7 is printed (Correct)
  • The program runs fine but nothing is printed
  • Error because the proper syntax for name mangling hasn't been implemented
  • Error because private class members can't be accessed

Answer :The program runs fine and 8.7 is printed

What is the output of the following piece of code when executed in the Python shell?


Options are :

  • Invalid method for classes
  • False
  • True (Correct)
  • Wrong syntax for isinstance() method

Answer :True

Python Certification Exam Preparation Set 26

What is the output of the following piece of code?


Options are :

  • test of B called test of C called test of A called (Correct)
  • Error, all the three classes from which D derives has same method test()
  • test of C called test of B called
  • est of B called test of C called

Answer :test of B called test of C called test of A called

What is the output of the following piece of code?


Options are :

  • Syntax error
  • Demo's check Derived's check (Correct)
  • Derived's check Demo's check
  • Demo's check Demo's check

Answer :Demo's check Derived's check

Which operator is overloaded by __invert__()?


Options are :

  • ~ (Correct)
  • ^
  • !

Answer :~

Python Certification Exam Preparation Set 46

What is the output of the following code?


Options are :

  • The program has an error because there isn't any function to return self.a
  • The program runs fine and 1 is printed
  • The program has an error because b is private and display(self) is returning a private member
  • The program has an error because b is private and hence can't be printed (Correct)

Answer :The program has an error because b is private and hence can't be printed

What is the output of the following code?


Options are :

  • Nothing is printed
  • __str__ called
  • Error
  • __repr__ called (Correct)

Answer :__repr__ called

What is the output of the following piece of code?


Options are :

  • Error, both the classes from which D derives has same method test()
  • test of B called test of C called
  • test of C called test of B called
  • test of B called (Correct)

Answer :test of B called

Python Certification Exam Preparation Set 54

The output of the code shown below is:


Options are :

  • TypeError
  • ImportError
  • NameError
  • ValueError (Correct)

Answer :ValueError

Methods of a class that provide access to private members of the class are called as ______ and ______


Options are :

  • getters/setters (Correct)
  • __init__/__del__
  • user-defined functions/in-built functions
  • __repr__/__str__

Answer :getters/setters

Which of the following best describes polymorphism?


Options are :

  • Focuses on variables and passing of variables to functions
  • Ability of a class to derive members of another class as a part of its own definition
  • Means of bundling instance variables and methods in order to restrict access to certain class members
  • Allows for objects of different types and behaviour to be treated as the same general type (Correct)

Answer :Allows for objects of different types and behaviour to be treated as the same general type

Python Certification Exam Preparation Set 8

A class in which one or more methods are only implemented to raise an exception is called an abstract class. True or False?


Options are :

  • True (Correct)
  • False

Answer :True

What is hasattr(obj,name) used for?


Options are :

  • To check if an attribute exists or not (Correct)
  • To set an attribute
  • To access the attribute of the object
  • To delete an attribute

Answer :To check if an attribute exists or not

What is the output of the following piece of code?


Options are :

  • Error, invalid syntax for object declaration
  • 1
  • Error, private class member can't be accessed in a subclass (Correct)
  • 0

Answer :Error, private class member can't be accessed in a subclass

Python Certification Exam Preparation Set 55

Which of the following is the most suitable definition for encapsulation?


Options are :

  • Focuses on variables and passing of variables to functions
  • Ability of a class to derive members of another class as a part of its own definition
  • Means of bundling instance variables and methods in order to restrict access to certain class members (Correct)
  • Allows for implementation of elegant software that is well designed and easily modified

Answer :Means of bundling instance variables and methods in order to restrict access to certain class members

What is the output of the following code?


Options are :

  • The program runs fine but nothing is printed
  • The program runs fine and 5 is printed (Correct)
  • The program has an error because display() is trying to print a private class member
  • The program has an error because display() can't be accessed

Answer :The program runs fine and 5 is printed

What is delattr(obj,name) used for?


Options are :

  • To print deleted attribute
  • To delete an attribute (Correct)
  • To check if an attribute is deleted or not
  • To set an attribute

Answer :To delete an attribute

Python Certification Exam Preparation Set 26

What is the output of the following piece of code?


Options are :

  • Error, class member x has two values
  • 3
  • Error, protected class member can't be accessed in a subclass
  • 5 (Correct)

Answer :5

What is the output of the following code?


Options are :

  • The program has an error as you can't name a class member using __b
  • The program has an error because there isn't any function to return self.a
  • The program has an error because b is private and display(self) is returning a private member
  • The program runs fine and 1 is printed (Correct)

Answer :The program runs fine and 1 is printed

Which of the following statements is true?


Options are :

  • The __eq(other) method is defined in the object class
  • The __init__ method is defined in the object class (Correct)
  • The __new__() method automatically invokes the __init__ method

Answer :The __init__ method is defined in the object class

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 23

Which of these is a private data field?


Options are :

  • __d__
  • __a
  • __b (Correct)
  • __c__

Answer :__b

Which of the following is not a class method?


Options are :

  • Static
  • Non-static (Correct)
  • Unbounded
  • Bounded

Answer :Non-static

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions