Python Certification Exam Preparation Set 16

Is the following Python code valid?


Options are :

  • no, finally must come before except
  • no, finally cannot be used with except (Correct)
  • no, there is no such thing as finally
  • yes

Answer :no, finally cannot be used with except

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

What will be the output of the following Python code?

a)

b)

c)

d)


Options are :

  • a
  • c
  • d
  • b (Correct)

Answer :b

What is hasattr(obj,name) used for?


Options are :

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

Answer :To check if an attribute exists or not

Which of the following statements is true?


Options are :

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

Answer :The __eq(other) method is defined in the object class

Python Certification Exam Preparation Set 16

When defining a subclass in Python that is meant to serve as a subtype, the subtype Python keyword is used.


Options are :

  • True
  • False (Correct)

Answer :False

Which of the following Python code creates an empty class?
a)

b)

c)

d) It is not possible to create an empty class


Options are :

  • c
  • a
  • b (Correct)
  • d

Answer :b

What is the output of the following piece of code?


Options are :

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

Answer :30

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

What is the output of the following piece of code?


Options are :

  • 1
  • 2 (Correct)
  • An exception is thrown
  • 11

Answer :2

What will be the output of the following Python code?


Options are :

  • 1 0
  • 1 2 (Correct)
  • Error, the syntax of the invoking method is wrong
  • The program runs fine but nothing is printed

Answer :1 2

Is the following Python code valid?


Options are :

  • no, there is no such thing as else
  • Yes (Correct)
  • no, else must come before except
  • no, else cannot be used with except

Answer :Yes

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

What does built-in function help do in context of classes?


Options are :

  • Determines the class identifiers of any value
  • Determines class description of any built-in type (Correct)
  • Determines the object name of any value
  • Determines class description of any user-defined built-in type

Answer :Determines class description of any built-in type

What is getattr() used for?


Options are :

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

Answer :To access the attribute of the object

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


Options are :

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

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

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

What are the methods which begin and end with two underscore characters called?


Options are :

  • In-built methods
  • User-defined methods
  • Additional methods
  • Special methods (Correct)

Answer :Special methods

Special methods need to be explicitly called during object creation.


Options are :

  • True
  • False (Correct)

Answer :False

What will be the output of the following Python code?


Options are :

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

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

Python Certification Exam Preparation Set 43

The purpose of name mangling is to avoid unintentional access of private class members.


Options are :

  • False
  • True (Correct)

Answer :True

What will be the output of the following Python code?


Options are :

  • error (Correct)
  • after f?
  • No output
  • after f

Answer :error

Which of the following blocks will be executed whether an exception is thrown or not?


Options are :

  • finally (Correct)
  • except
  • assert
  • else

Answer :finally

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

What will be the output of the following Python code?


Options are :

  • 7 (Correct)
  • 0
  • Error
  • 6
  • 9

Answer :7

What will be the output of the following Python code?

a)

b)

c) test of B called
d) Error, both the classes from which D derives has same method test()


Options are :

  • d
  • a
  • b
  • c (Correct)

Answer :c

What will be the output of the following Python code?


Options are :

  • A disp() (Correct)
  • Nothing is printed
  • Error because when object is created, argument must be passed
  • Invalid syntax for inheritance

Answer :A disp()

Python Certification Exam Preparation Set 12

Which operator is overloaded by __invert__()?


Options are :

  • !
  • ~ (Correct)
  • ^

Answer :~

What will be the output of the following Python code?


Options are :

  • The program runs fine and 1 is printed (Correct)
  • 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 hence can't be printed
  • The program has an error because b is private and display(self) is returning a private member

Answer :The program runs fine and 1 is printed

What is the output of the following piece of code?


Options are :

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

Answer :Demo's check Derived's check

Python Certification Exam Preparation Set 31

Which of these is not a fundamental features of OOP?


Options are :

  • Inheritance
  • Polymorphism
  • Instantiation (Correct)
  • Encapsulation

Answer :Instantiation

What is the output of the following piece of code?


Options are :

  • 1 1 1
  • '1' '1' '1'
  • An exception is thrown
  • 1 2 3 (Correct)

Answer :1 2 3

What will be the output of the following Python code?


Options are :

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

Answer :__str__ called

Python Certification Exam Preparation Set 19

What will be the output of the following Python code?


Options are :

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

Answer :5

What type of inheritance is illustrated in the following Python code?


Options are :

  • Multiple inheritance (Correct)
  • Hierarchical inheritance
  • Multi-level inheritance
  • Single-level inheritance

Answer :Multiple inheritance

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions