PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 73


What is the expected output of the following snippet?

Show Answer
Correct Answer: B

In this code, three classes X, Y, and Z are defined. Class Y inherits from class X, and class Z inherits from class Y. Two instances, x and z, are created as objects of class Z. The isinstance function is used to check if x is an instance of Z (which it is) and if z is an instance of X (which it is, since Z inherits from Y and Y inherits from X). So, the expected output is 'True True'.

Discussion

14 comments
Sign in to comment
WillyNilly69Option: B
Jun 28, 2020

serious capitalization typos, however the correct answer is B. class X: pass class Y(X): pass class Z(Y): pass x = Z() z = Z() print(isinstance (x, Z), isinstance (z, X)) >>>True True

apextek1Option: B
Mar 16, 2020

Should be B

imsaadOption: B
Aug 10, 2020

Correct answer is B. True True

zantrzOption: B
Jan 31, 2024

B True True. In this code: There are three classes: X, Y, and Z. Class Y inherits from class X, and class Z inherits from class Y. Two instances, x and z, are created as objects of class Z. The isinstance function is then used to check the types of these instances. Here's the breakdown: x = Z(): This line creates an instance of class Z and assigns it to the variable x. z = Z(): This line creates another instance of class Z and assigns it to the variable z. Now, let's look at the print statement: print(isinstance(x, Z), isinstance(z, X)): This line checks if x is an instance of Z (which it is, as x was instantiated from class Z). It also checks if z is an instance of X (which it is, as Z inherits from Y and Y inherits from X). So, the output of this code will be: B True True.

Het_is_je_boy
Aug 22, 2020

Should be NameError: name 'x' is not defined.

Het_is_je_boy
Aug 22, 2020

If you do: class X: pass class Y(X): pass class Z(Y): pass x = Z() z = Z() print(isinstance(x,Z), isinstance(z,X)) you get back True True So B

dougie_fr3sh
Dec 24, 2021

Please fix these typo's.

TheNetworkStudentOption: B
Mar 6, 2022

True True indeed, tested it and that's the result when all typos are corrected. B is correct

rocky48Option: B
Mar 9, 2022

If you do: class X: pass class Y(X): pass class Z(Y): pass x = Z() z = Z() print(isinstance(x,Z), isinstance(z,X)) >> True True So B is the answer

mbacelarOption: B
Apr 6, 2022

True True

Norasit
Apr 25, 2022

I try to focus on x, X, z, Z. There is no any correct answer.

macxszOption: B
May 3, 2022

B. True True

palagusOption: B
May 24, 2022

The answer is B

JnanadaOption: B
Aug 18, 2022

Should be B

MallieOption: B
Dec 22, 2022

Answer is B....if it wasn't for the typos.