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 trialNOIR TRADI
374 Pointswhy 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)
print (add_two(10))
6 Answers
KRIS NIKOLAISEN
54,972 PointsWhen 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))
Josh Keenan
20,315 PointsCan you tell me what the second input is?
NOIR TRADI
374 Pointsprint(add_two(10))
Ary de Oliveira
28,298 Points# ====> 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
Ben Bassler
1,806 PointsPlease tell me what you passed in as an argument for add_two() when it outputted 'None'.
NOIR TRADI
374 Pointsprint(add_two(10))
KRIS NIKOLAISEN
54,972 PointsThis 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.
NOIR TRADI
374 Pointsthanks guys!!
NOIR TRADI
374 PointsNOIR TRADI
374 Pointsdef add_two(num): val = num + 2 print(val)
print (add_two(10))
RESULT IS...
treehouse:~/workspace$ python functions.py
12
None
why None???