0

The following prints out "None" instead of "whatever". I don't understand why.

dirr = None

def method():
    global dirr # you have to declare that you'll use global variable 'dirr'
    dirr = "whatever"

print `dirr`
1
  • 2
    you have to call the method first before print(dirr) Commented Apr 27, 2019 at 1:43

1 Answer 1

1

You should call 'method' one time.

dirr = None

def method():
    global dirr # you have to declare that you'll use global variable 'dirr'
    dirr = "whatever"

method()
print (dirr)

The result is:

whatever
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.