Clarification - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Clarification (/thread-5943.html) |
Clarification - Hammuel - Oct-29-2017 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 RE: Clarification - Lux - Oct-29-2017 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: ".
RE: Clarification - Hammuel - Oct-30-2017 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 |