Python Functions, Packing, and Unpacking Introduction to Functions Let's Talk About Scope

Justin McKenzie
Justin McKenzie
6,724 Points

Just a head's up, there's no print method here even though the video implies something will be printed out when running

Might confuse some people, just wanted to give you the head's up since I'm using this on the beta version

Brice Roberts
Brice Roberts
22,415 Points

For anyone who has racked their brain over this....

num = 10


def set_num():
    num = 5
    print("num is {} in the local scope.".format(num))


set_num()   #calling the function


print("But, outside of the function's scope num is {}".format(num))   #calling num that is instantiated on the first line
Md. Syful Islam
Md. Syful Islam
9,360 Points

Thank you, you have cleared something that could raise confusion. (y)

3 Answers

tomtrnka
tomtrnka
9,780 Points

She's talking about workspace, where the print method is present and you can run it without trouble.

num = 10

def set_num():
    num = 5

set_num()

print(num)
def print_name():
    print('Ary de Oliveira')

def print_favorite_name():
    print('Ary')


print_name()
print_favorite_name()

Your block of code is not relevant to what he's referring to.

Tamara Orujzade
Tamara Orujzade
1,138 Points

Correct. My workspace didn't print anything without the print statement.