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.
why second output is NONE? def add_two(num): val = num + 2 print(val) print (add_two(10))
tell me please why first output is 10(right) and second is NONE?
def add_two(num): val = num + 2 print(val)
When a function doesn't have a return statement the default return value is None. The following will print 12 in both cases.
def add_two(num): val = num + 2 print(val) return val print(add_two(10))
# ====> in global scope. # ====> When a function doesn't have a return # statement the default return value is None. def print_name(): print('Ary de Oliveira') def print_favorite_name(): print('Ary') numero = 120 def set_numero(): numero = 60 key = 'a' print(key) print(set_numero()) print(numero) print_name() print_favorite_name() my_var = 10 def multiply(): my_var = 10 * 2 print(my_var) #ary
Please tell me what you passed in as an argument for add_two() when it outputted 'None'.
This has already been answered. Your add_two() function returns None because it has no explicit return statement. As a result print(add_two(10)) displays None.