Exam PCAP All QuestionsBrowse all questions from this exam
Question 28

What is the expected behavior of the following snippet?

It will:

    Correct Answer: D

    D

Discussion
clacotOption: D

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

lasagne394

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

clear now. Thanks!

G3n

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!

natlalOption: D

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

34_trtOption: D

D.prints 3

macxszOption: D

D. print 3

wolverin3Option: A

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.