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

Why do I get a "None" output in this script?

first_name = input(print("Type your first name here"))
last_name = input(print("Type your last name here"))
print( first_name, last_name, "is learning Python")

2 Answers

first_name = input("Type your first name here") will print the string "Type your first name here" to the console and store the user's input in the variable first_name. You don't need to use the print function with the input function.

When you pass the print function to the input function, the input function will evaluate the print function and print its value to the console. The print function prints the string "Type your first name here" to the console and returns the value None to the input function, which then prints out the return value None and then takes user input.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

Yep!

>>> foo = input(print("Enter name > "))
Enter name >     # output of print statement includes newline character
Nonestewart      # None printed followed by user input "stewart"
>>> foo
'stewart'

print( None, "None")