Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification
#1
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
Reply
#2
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: ".
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can I get some clarification on importing functions from external files. wh33t 3 859 Feb-25-2023, 08:07 PM
Last Post: deanhystad
  Looking for clarification related to performance Pymon 5 1,996 Apr-04-2022, 04:47 PM
Last Post: deanhystad
  Read Tensorflow Documentation - Clarification IoannisDem 0 1,154 Aug-20-2021, 10:36 AM
Last Post: IoannisDem
  *args implementation and clarification about tuple status amjass12 10 3,913 Jul-07-2021, 10:29 AM
Last Post: amjass12
  Just need some clarification Tonje 3 2,011 Oct-01-2020, 03:52 PM
Last Post: deanhystad
  Global Variables - Some Points Needing Clarification. adt 4 2,892 Nov-30-2019, 01:23 PM
Last Post: adt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020