python return dose not work saying "blabla is not defined"

Question:

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.

Asked By: Jas0n

||

Answers:

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

Answered By: Rohan Mukherjee
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.