1

As you know, a user input in Python by default is a string. I tried converting them using the int() function after, however, it still stays as a string. Code example:

number = input("Input a number: ")
int(number)
print(type(number))

This would give an output of: <class 'str'> , even though I tried converting them to an integer.

Cris
  • 39
  • 1
  • 1
  • 8

2 Answers2

1

You need to assign the value, because int() doesn't apply on place.

number = int(number)

Python int() function

vszholobov
  • 2,133
  • 1
  • 8
  • 23
0

You also need to assign the converted variable to your number:

number = input("Input a number: ")
number = int(number)
print(type(number))

Or directly like this:

number = int(input("Input a number: "))
print(type(number))
Marc
  • 338
  • 2
  • 15
  • Whoops, somebody postet the answer a minute faster than me. How should I proceed? Delete my answer or leave it? @ExperiencedUserdOfSO :) – Marc Aug 03 '21 at 02:33