Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,463 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)
Tamara Orujzade
Tamara Orujzade
1,139 Points

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

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.