Python · Question 26 · Medium

What will be the output of the following Python code?

x = 5

def f():
    global x
    x += 2
    return x * 2

print(f(), x)
  1. 7 14
  2. 14 5
  3. 10 5
  4. 14 7
Answer and explanation

Answer: D. 14 7

Explanation: Arguments are evaluated left to right. f() changes the global x to 7 and returns 14; then x is read as 7. The output is 14 7.

Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?

Practise python

Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.

More python questions

More technical & programming practice

Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge