Computer Science

Find and write the output of the following python code :

a = 10
def call(): 
    global a
    a = 15
    b = 20
    print(a) 
call()

Python

Python Functions

3 Likes

Answer

15

Working

  1. a = 10 — This line assigns the value 10 to the global variable a.
  2. def call() — This line defines a function named call.
  3. a = 15 — Inside the call function, this line assigns the value 15 to the global variable a. As global keyword is used earlier, this assignment modifies the value of the global variable a.
  4. b = 20 — Inside the call function, this line assigns the value 20 to a local variable b.
  5. print(a) — This line prints the value of the global variable a, which is 15. This is because we've modified the global variable a inside the call function.

Answered By

2 Likes


Related Questions