Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.