Python Certification Exam Preparation Set 35

What can we deduce from the following snippet? Select the true sentences. (select all that apply)


Options are :

  • A. The program will print the mathematical constant ? = 3.141592..., to available precision
  • B. The program will cause a runtime exception/error (Correct)
  • C. The program makes an alias for the name pi in the form of xyz (Correct)
  • D. The original name pi will become inaccessible (Correct)
  • E. Replacing line 02 with print(xyz) will cause the program to run without errors (Correct)

Answer :B. The program will cause a runtime exception/error C. The program makes an alias for the name pi in the form of xyz D. The original name pi will become inaccessible E. Replacing line 02 with print(xyz) will cause the program to run without errors

What is true about the __init__.py file? (Select all that apply)


Options are :

  • A. It cannot be an empty file
  • B. It can execute an initialization code for a package (Correct)
  • C. It is required to make Python treat a given directory as a Python package directory (Correct)
  • D. It is required to make Python treat a given directory containing packages as a directory without packages

Answer :B. It can execute an initialization code for a package C. It is required to make Python treat a given directory as a Python package directory

What is the expected behavior of the following code snippet?


Options are :

  • A. The program will generate a sequence of ten (pseudo)random integers from 1 to 5
  • B. The program will generate a sequence of ten (pseudo)random integers from 1 to 4
  • C. The program will generate a sequence of ten (pseudo)random numbers from 1 to 5
  • D. The program will generate a sequence of ten (pseudo)random numbers from 1 to 4
  • E. The result cannot be predicted
  • F. The program will cause a runtime exception/error (Correct)

Answer :F. The program will cause a runtime exception/error

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

What is the expected behavior of the following snippet?

It will:


Options are :

  • A. print 8 (Correct)
  • B. print 4
  • C. print 6
  • D. cause a runtime exception on line 4
  • E. cause a runtime exception on line 5

Answer :A. print 8

What is the expected behavior of the following snippet?

It will:


Options are :

  • A. print hello
  • B. print h
  • C. print ello
  • D. cause a runtime exception on line 2
  • E. cause a runtime exception on line 3
  • F. cause a runtime exception on line 4
  • G. cause a runtime exception on line 5 (Correct)

Answer :G. cause a runtime exception on line 5

What is the expected behavior of the following snippet?


Options are :

  • A. It will print: SPAM
  • B. It will print: MAPS
  • C. It will print: None
  • D. It will print: SPAMMAPS (Correct)
  • E. It will print: SPAM MAPS
  • F. It will cause a runtime exception/error
  • G. It will print an empty line

Answer :D. It will print: SPAMMAPS

Python Certification Exam Preparation Set 13

Select the true statements:

(select all that apply)


Options are :

  • A. Positional arguments are also called keyword arguments
  • B. The order of arguments matters when they are passed positionally (Correct)
  • C. The order of arguments matters when they are passed by their name
  • D. A function can be called with a mix of positional and keyword arguments (Correct)

Answer :B. The order of arguments matters when they are passed positionally D. A function can be called with a mix of positional and keyword arguments

What is the expected behavior of the following snippet?


Options are :

  • A. It will print: B. It will print: 014916 C. It will print: 0 1 4 9 16
  • D. It will cause a runtime exception/error (Correct)
  • E. It will print an empty line

Answer :D. It will cause a runtime exception/error

Select the true statements: (select all that apply)


Options are :

  • A. The class keyword marks the beginning of the class definition (Correct)
  • B. An object cannot contain any references to other objects
  • C. A class may define an object (Correct)
  • D. A constructor is used to instantiate an object (Correct)
  • E. An object variable is a variable that is stored separately in every object

Answer :A. The class keyword marks the beginning of the class definition C. A class may define an object D. A constructor is used to instantiate an object

Python Certification Exam Preparation Set 36

Select the true statements: (select all that apply)


Options are :

  • A. Inheritance means passing attributes and methods from a superclass to a subclass (Correct)
  • B. issubclass(class1, class2) is an example of a function that returns Trueif class2 is a subclass of class1
  • C. Multiple inheritance means that a class has more than one superclass (Correct)
  • D. Polymorphism is the situation in which a subclass is able to modify its superclass behavior (Correct)
  • E. A single inheritance is always more difficult to maintain than a multiple inheritance

Answer :A. Inheritance means passing attributes and methods from a superclass to a subclass C. Multiple inheritance means that a class has more than one superclass D. Polymorphism is the situation in which a subclass is able to modify its superclass behavior

Select the true statements: (select all that apply)


Options are :

  • A. A class definition may have any number of constructors, but their names must be unique
  • B. It is not possible to safely check if an object has a certain attribute
  • C. A class constructor cannot return a value (Correct)
  • D. __bases__ is a tuple filled with the names of all the direct superclasses (Correct)
  • E. issubclass(c1, c2) is a function that checks if c1 is an object derived from class c2

Answer :C. A class constructor cannot return a value D. __bases__ is a tuple filled with the names of all the direct superclasses

What will happen when you run each of the following code snippets?


Options are :

  • A. A ZeroDivisionError exception will be raised in Example 1, while Example 2 will print 0 to the screen
  • B. A ZeroDivisionError exception will be raised in Example 2, while Example 1 will print 0 to the screen
  • C. A ZeroDivisionError exception will be raised in Example 1 and Example 2 (Correct)
  • D. A ValueError exception will be raised in Example 1, and a ZeroDivisionError exception will be raised in Example 2
  • E. A ValueErrorexception will be raised in Example 2, and a ZeroDivisionError exception will be raised in Example 1

Answer :C. A ZeroDivisionError exception will be raised in Example 1 and Example 2

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

What is the expected output of the following code?

The program will print the following to the screen:


Options are :

  • A. 1 2
  • B. ERROR MESSAGE 1 2
  • C. 0 2
  • D. 0 ERROR MESSAGE 1 2 (Correct)

Answer :D. 0 ERROR MESSAGE 1 2

The following class hierarchy is given. What is the expected output of the code?



Options are :

  • A. AB
  • B. ABB (Correct)
  • C. BA
  • D. BBA
  • E. AAA
  • F. BBB

Answer :B. ABB

If the following snippet is executed and the exception is raised


we will see:


Options are :

  • A. two identical non-empty lines
  • B. two different non-empty lines
  • C. two empty lines
  • D. one non-empty line and one empty line (Correct)

Answer :D. one non-empty line and one empty line

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

Is there any difference in the error messages displayed once the two newly defined exceptions CriticalError have been raised separately?



Options are :

  • A. No, both errors raised will display the same message: ERROR MESSAGE A
  • B. No, both errors raised will display the same message: ERROR MESSAGE B
  • C. No, both errors raised will display no message
  • D. Yes, the first error raised will display the message ERROR MESSAGE A, while the second ERROR MESSAGE B (Correct)
  • E. Yes, the first error raised will display no message, while the second ERROR MESSAGE B
  • F. Yes, the first error raised will display no message, while the second ERROR MESSAGE A

Answer :D. Yes, the first error raised will display the message ERROR MESSAGE A, while the second ERROR MESSAGE B

You want to access the test.txt file and retrieve each line in it. Which option will you use? (Select all that apply)


Options are :

  • A. print(file.readlines()) (Correct)
  • B. print(readlines(file))
  • C. print(file.readlines(:)
  • D. for l in file: print(l) (Correct)
  • E. print(file.lines())
  • F. print(file.read()) (Correct)
  • G. print(read.file(test.txt))

Answer :A. print(file.readlines()) D. for l in file: print(l) F. print(file.read())

The following code snippet when run

will (select all that apply): 


Options are :

  • A. open the file file.txt in write mode (Correct)
  • B. delete the file contents if the file file.txt already exists (Correct)
  • C. leave the file contents unchanged if the file file.txt already exists
  • D. create the file file.txt if it does not exist (Correct)
  • E. raise the FileNotFoundError exception if the file does not exist

Answer :A. open the file file.txt in write mode B. delete the file contents if the file file.txt already exists D. create the file file.txt if it does not exist

Python Certification Exam Preparation Set 35

And operator able to perform bitwise shifts is coded as (Select two answers)


Options are :

  • --
  • ++
  • << (Correct)
  • >> (Correct)

Answer :<< >>

Python Certification Exam Preparation Set 23

Which of the following literals reflect the value given as 34.23? (Select two answers)


Options are :

  • .3423e2 (Correct)
  • 3423e-2 (Correct)
  • .3423e-2
  • 3423e2

Answer :.3423e2 3423e-2

What is the expected output of the following snippet?


Options are :

  • 3 (Correct)
  • 1
  • 2
  • the code is erroneous

Answer :3

Which of the following statements are true? (Select two answers)


Options are :

  • Python strings are actually lists
  • Python strings can be concatenated (Correct)
  • Python strings can be sliced like lists (Correct)
  • Python strings are mutable

Answer :Python strings can be concatenated Python strings can be sliced like lists

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

Which of the following sentences are true? (Select two answers)


Options are :

  • Lists may not be stored inside tuples
  • Tuples may be stored inside lists (Correct)
  • Tuples may not be stored inside tuples
  • Lists may be stored inside lists (Correct)

Answer :Tuples may be stored inside lists Lists may be stored inside lists

You need data which can act as a simple telephone directory. You can obtain it with the following clauses (Select two relevant variants; assume that no other items have been created before)


Options are :

  • dir={"˜Mom': 5551234567, "˜Dad': 5557654321} (Correct)
  • dir= {"˜Mom': "˜5551234567', "˜Dad': "˜5557654321'} (Correct)
  • dir= {Mom: 5551234567, Dad: 5557654321}
  • dir= {Mom: "˜5551234567', Dad: "˜5557654321'}

Answer :dir={"˜Mom': 5551234567, "˜Dad': 5557654321} dir= {"˜Mom': "˜5551234567', "˜Dad': "˜5557654321'}

A file name like this one below says that:


(Select three answers)


services, cpython 36.pyc


Options are :

  • the interpreter used to generate the file is version 3.6 (Correct)
  • it has been produced by CPython (Correct)
  • it is the 36 version of the file
  • the file comes from the services.py source file (Correct)

Answer :the interpreter used to generate the file is version 3.6 it has been produced by CPython the file comes from the services.py source file

Python Certification Exam Preparation Set 45

If you want to access an exception object's components and store them in an object called e, you have to use the following form of exception statement:


Options are :

  • except Exception (e) :
  • except e= Exception :
  • such an action is not possible in Python
  • except Exception as e: (Correct)

Answer :except Exception as e:

A variable stored separately in every object is called:


Options are :

  • there are no such variables, all variables are shared among objects
  • a class variable
  • an object variable
  • an instance variable (Correct)

Answer :an instance variable

There is a stream named s open for writing. What option will you select to write a line to the stream?


Options are :

  • s. write ("Hello\n") (Correct)
  • write (s, "Hello")
  • s.writeln ("Hello")
  • s. writeline ("Hello")

Answer :s. write ("Hello\n")

Python Certification Exam Preparation Set 27

You are going to read just one character from a stream called s. Which statement would you use?


Options are :

  • ch = read (s, 1)
  • ch= s.input (1)
  • ch= input (s, 1)
  • ch= s.read (1) (Correct)

Answer :ch= s.read (1)

Python strings can be "glued" together using the operator:


Options are :

  • .
  • &
  • _
  • + (Correct)

Answer :+

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions