Python inputs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 14

Python inputs

is input always string even if i dont define it as string and the user input is digit (integer)?

1st Jul 2018, 9:30 PM
Goshgar Mikayilov
Goshgar Mikayilov - avatar
19 Answers
1st Jul 2018, 10:46 PM
Oma Falk
Oma Falk - avatar
+ 16
Yes. Function input() always return a string. If this string is completely made of numbers (int/float), you can convert it by int() or float().
1st Jul 2018, 9:48 PM
李立威
+ 9
def inputint(): return int(input("enter a num")) if you need more than once
1st Jul 2018, 10:38 PM
Oma Falk
Oma Falk - avatar
+ 6
how do could you define different?
1st Jul 2018, 10:19 PM
Oma Falk
Oma Falk - avatar
+ 1
input() always is a string, but int(input()) is always an integer. example: input: 1 2 code 1: var1 = input() var2 = input() print(var1+var2) output 1: 12 code 2: var1 = int(input()) var2 = int(input()) print(var1+var2) output 2: 3
15th Mar 2022, 1:53 AM
Окилов Мухаммад
Окилов Мухаммад - avatar
+ 1
x=1000000 y=0.01*(2**30) print(max(x,y))
15th Jun 2022, 5:58 AM
Subhas Pramanik
Subhas Pramanik - avatar
+ 1
Hello
24th Oct 2022, 12:10 PM
Anush Grigoryan
Anush Grigoryan - avatar
0
thanks i got it
3rd Jul 2018, 2:28 AM
Goshgar Mikayilov
Goshgar Mikayilov - avatar
0
input () function automatically takes inputs as a string. If you want to take integer input then use int(input()) and to take float as input, just use float (input ()). That's it. Pretty simple.
2nd Dec 2021, 4:49 PM
Prithviraj Kundu
Prithviraj Kundu - avatar
0
I can help you. You need to write: int(input("text"))
30th Jan 2022, 4:22 AM
Тимур Валиев
Тимур Валиев - avatar
0
Yes , you can use int(input()) to define it as integer
14th Feb 2022, 9:33 AM
Kouros Zanbouri
Kouros Zanbouri - avatar
0
Yes, because 'string' has been set as default category for input() statement for making or asking integer or float value you may use the following functions alongwith input(): int() for integers float() for floating point literals eval() for both
22nd Feb 2022, 3:21 PM
Jaya
Jaya - avatar
0
I am new to the platform....please i need more explanations
29th Jun 2022, 6:37 PM
Popoola Olamide
Popoola Olamide - avatar
0
Yes. Function input() always return a string. If this string is completely made of numbers (int/float), you can convert it by int() or float().
5th Aug 2022, 3:06 AM
Azat Zeinilov
Azat Zeinilov - avatar
0
Yes. Input function is always a string. If the string is having numbers (int/float), we can convert it bu int() or float().
12th Nov 2022, 5:01 AM
Avanit Singh
Avanit Singh - avatar
0
Yep , python assign the input value to string if you won't define it
18th Nov 2022, 7:18 PM
Kr$na
Kr$na - avatar
0
Yes. Input() means already it takes as a "string" type. If you need to get values from different types, as a ex: int(input()) According to the above code, we can get input as a integer.
25th Nov 2022, 7:54 PM
Pamuda U De A Goonatilake
Pamuda U De A Goonatilake - avatar
- 1
How do I use type-conversion to return a char from a string which contains a single letter? word="word" for w in word: letter=char(word)
27th Aug 2018, 5:46 PM
Jacob Turet
Jacob Turet - avatar
- 1
input() always is a string, but int(input()) is always an integer. example: input: 1 2 code 1: var1 = input() var2 = input() print(var1+var2) output 1: 12 code 2: var1 = int(input()) var2 = int(input()) print(var1+var2) output 2: 3
4th Oct 2021, 8:14 PM
fajnah6