PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 28


What is the expected behavior of the following snippet?

It will:

Show Answer
Correct Answer: D

D

Discussion

6 comments
Sign in to comment
clacotOption: D
Aug 12, 2020

I know we shouldn't use function name same as variable name. But if I run the code the result is 3. Why?

lasagne394
Aug 18, 2020

Because during an assignment, the RHS is evaluated first and the result is assignment to the given identifier. In this case, the `x` on the RHS was a function and the result (1 + x() = 1 + 2) was REASSIGNED/BOUND to the same identifier. Post reassignment, x is bound to a int literal, while before it was bound to a function. I hope this snippet will help: https://prnt.sc/u1u8ki

clacot
Aug 19, 2020

clear now. Thanks!

wolverin3Option: A
Nov 18, 2020

def x(i): print(i) return i x=x(1)+x(2) Expression is evaluated from left to right, function return takes more precedence then followed by operator and finally value is assigned which is of least precedence. Above example would illustrate it.

macxszOption: D
May 3, 2022

D. print 3

34_trtOption: D
Sep 30, 2023

D.prints 3

natlalOption: D
Jan 21, 2024

def x(): #x_function return 2 x=1+x() #x_value=use x_function print(x) #-->3 def x(): #x_function return 2 x=10 #x_value=int x=1+x() #x_value=use not exist x_function print(x) #-->TypeError: 'int' object is not callable

G3n
Jun 18, 2024

The answers in the dumps are good to remember! The bulk of the exam questions are from these exam dumps. The questions with mistakes in them or missing : etc are in the exam but in the correct answer form, do remember the correct answers as well as the answers with the mistakes in the coding. There are a few questions that are slightly different but you can find the answers from the previous or next question/answers! Hope this helps!