Report Bug

Qus

What will be the output of the following Python code?

  x = 5   def f1():      global x      x = 4  def f2(a,b):      global x      return a+b+x  f1()  total = f2(1,2)  print(total)
Qusनिम्नलिखित Python कोड का आउटपुट क्या होगा?


A. Error
B. 7
C. 8
D. 15


Solution
B. 7



Explanation
In the code shown above, the variable ‘x’ has been declared as a global variable under both the functions f1 and f2. The value returned is a+b+x = 1+2+4 = 7.
Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz