How to use input function as a integer in Python. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use input function as a integer in Python.

12th Sep 2020, 8:09 AM
Vishu
Vishu - avatar
3 Answers
+ 5
If you want to input more than 1 value, it can be done like this. The values from input will be integer and are stored in a list: You can use an input with split, map and int conversion or a list comprehension with int conversion: (1) input with split(), int conversion: inp = list(map(int, input('').split())) # input like: 1 3 12 (2) input with split(), int conversion and comprehension: inp = [ int(i) for i in input().split()] # input like: 1 3 12 Both versions have the result of: [1,3,12]
12th Sep 2020, 10:44 AM
Lothar
Lothar - avatar
+ 4
Number = int(input()) And everything remains the same.. you can also give the prompt message inside the input function
12th Sep 2020, 8:13 AM
Charitra
Charitra - avatar
+ 2
Var1 = int(input())
12th Sep 2020, 8:33 AM
Vishu
Vishu - avatar