Thursday , September 19 2024

What is the output of the following snippet? def any(): print(var + 1, end=”) var = 1 any() print(var)

Questions BankCategory: Python Essentials 1What is the output of the following snippet? def any(): print(var + 1, end=”) var = 1 any() print(var)
What is the output of the following snippet?

def any():
    print(var + 1, end='')
 
 
var = 1
any()
print(var)
  • 12
  • 11
  • 21
  • 22

Explanation: Let’s analyze the code:

  • the var variable is assigned the integer 1 as its value,
  • the any& function is invoked, and it executes the arithmetic operation 1+1 and prints the result 2 on the console. The instruction end=” prevents a newline jump,
  • the instruction print(var) prints 1 on the console.

More Questions: Python Essentials 1 – Module 4 Test