KnowledgeBoat Logo

Computer Science

In the following code, which variables are in the same scope ?

def func1():
    a = 1
    b = 2

def func2():
    c = 3
    d = 4
e = 5

Python Functions

4 Likes

Answer

In the code, variables a and b are in the same scope because they are defined within the same function func1(). Similarly, variables c and d are in the same scope because they are defined within the same function func2(). e being a global variable is not in the same scope.

Answered By

2 Likes


Related Questions