-2

So I'm studying Python and learning def and what it dose but when i try to run the following code

def test1():
    a = [" " , " " , " "]
    return a
test1()

print(a)

the error pop up saying that a is not defined.

Jas0n
  • 91
  • 1
  • 2
  • 10

1 Answers1

1

a is defined only in the scope of test1. You have to do a = test1() to store the value in a.

Rohan Mukherjee
  • 280
  • 2
  • 7