Python Forum

Full Version: Clarification
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This may seem like a stupid question.. But, I just started learning python today. And here is my dilemma, when coming across input I was confused as to why input would be used here and not str for example

name = input("What is your name: ")
age = int(input("How old are you: "))
year = str((2014 - age)+100)
print(name + " will be 100 years old in the year " + year)

Why wouldn't you use, name = str("What is your name: ")
Or could you use either and it is based off your preference, any clarification would be greatly appreciated
input() is a function that gets text input from the user. str() is a function that converts values to the 'String' type, just like int() converts values to integers.

If you used name = str("What is your name: ")name would be set to the sting "What is your name: ".
Okay, that makes sense, so they are putting int(input("How old are you: ")) because it is in string format but you want the input to be an integer, that makes sense, so like wise you could put name = str(input("What is your name: ")) but don't have to because it would already accept the input of a string. Thank you @Lux