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
Michael Thompson
1,499 Pointsinput() gives me an int without having to tell it to...
Usually I use a terminal window instead of Workspaces to follow along with the lessons. In the videos Kenneth says input() will always give you a string even if the user enters an int but my machine gives me an int and I have no problem incrementing it by one without having to convert it to an int.
I am using Python 2.7.5 so is input() always returning an string only in Python 3?
1 Answer
Alexander Davison
65,469 PointsIn Python 2, the "input" function won't be a string, so if you type in a variable name, the input will be that variable. If you want to do the input raw (in string form), you can use the "raw_input" function like this:
# Get raw input (input in string form)
my_input = raw_input("Enter your name: ")
# Print the input out
print("Hello {}!".format(my_input))
Hope that helps!
Michael Thompson
1,499 PointsMichael Thompson
1,499 PointsOk I think I get it: input() performs the function in Python 3 that raw_input() performs in Python 2. I need to update my Python version! Thanks Alexander.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem! I used to have the same problem too.