Python Forum
storing input as a integer help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
storing input as a integer help
#2
input() always returns a str. It doesn't matter what you type, it's a str.
>>> x = input("?")
?43
>>> x
'43'
>>> type(x)
<class 'str'>
If you want a number, then you'll need to convert it to one first:
>>> x = int(input("?"))
?42
>>> x
42
>>> type(x)
<class 'int'>
Reply


Messages In This Thread
storing input as a integer help - by faputting - Feb-23-2018, 06:30 PM
RE: storing input as a integer help - by nilamo - Feb-23-2018, 06:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Verify input as integer and not blank GMCobraz 3 2,162 Jun-22-2020, 02:47 PM
Last Post: pyzyx3qwerty
  Mixed string,Integer input variable issue maderdash 2 2,781 Nov-06-2018, 09:46 AM
Last Post: snippsat
  Changing User Input Strings Into Set Integer Values Mario128843 3 3,196 May-01-2018, 03:32 AM
Last Post: Mario128843
  Storing float as integer in a database Ageir 6 5,329 Aug-17-2017, 08:03 PM
Last Post: Ageir
  why does integer input give error invalid literal for int() PyPhanman 2 6,218 Apr-27-2017, 05:32 AM
Last Post: ndc85430
  Taking user input and storing that to a variable then storing that variable to a list jowalk 12 37,403 Mar-27-2017, 11:45 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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