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 Getting Info In and Out of Functions Arguments and Parameters

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)

print (add_two(10))

def add_two(num): val = num + 2 print(val)

print (add_two(10))

RESULT IS...

treehouse:~/workspace$ python functions.py
12
None

why None???

6 Answers

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))
Josh Keenan
Josh Keenan
19,652 Points

Can you tell me what the second input is?

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'.

print(add_two(10))

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.

thanks guys!!