PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Medium

Question 11

Assume that the following piece of code has been successfully executed:



What is the expected output of the following piece of code?



  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

A.

  • issubclass(LandVehicle, Vehicle): This returns True because LandVehicle is a subclass of Vehicle.

  • issubclass(LandVehicle, AirVehicle): This returns False because LandVehicle and AirVehicle are both subclasses of Vehicle, but LandVehicle is not a subclass of AirVehicle.

  • isinstance(veh2, Vehicle): This returns True because veh2 is an instance of LandVehicle, which is a subclass of Vehicle.

  • isinstance(veh3, Vehicle): This returns True because veh3 is an instance of AirVehicle, which is also a subclass of Vehicle.

B.

This is incorrect. The issubclass(LandVehicle, Vehicle) check should return True, because LandVehicle is a subclass of Vehicle.

C.

This is incorrect. The issubclass(LandVehicle, AirVehicle) check should return False, as LandVehicle is not a subclass of AirVehicle.

D.

This is incorrect. The isinstance checks should return True because both veh2 and veh3 are instances of classes that are subclasses of Vehicle.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need