+ 11

Why is the output of an input always a string?

4th Feb 2018, 7:38 PM
Maria Leonor
30 Answers
+ 56
The input() function takes in input from standard in (keyboard in console) and returns a string stripping the newline character from the input. If you need what was input by the user to be of a different type then you must convert it. I.E. int(input()) to convert the users input to an integer. https://docs.python.org/3/library/functions.html scroll down to input() The standard input and output streams can only deal with objects that can be utilized within the stream. In this case str. So, all values received from the standard input will be returned as a string (str) and all values sent to standard output (console window) will be converted to a string (str) and then inserted into the stream. The conversion, when using standard output, happens after all the operations have completed and is then done implicitly.
4th Feb 2018, 8:15 PM
ChaoticDawg
ChaoticDawg - avatar
+ 6
that isn't right, you can make it int just write: int(input()) this how you make the input int. like this: input() it's a string.
27th Jun 2021, 3:11 PM
Mr.Max
Mr.Max - avatar
+ 4
When we use input() function alone then it converts the data as default i.e., as string that's why if we need integer or float value, we make use of int(), float or eval() function along with input() so as to get desired output
22nd Feb 2022, 3:09 PM
Jaya Vishwakarma
Jaya Vishwakarma - avatar
+ 3
Python by default takes input as a string due to its configuration, however, you can program it in such a way that the string is automatically converted into whatever you want.Be it integer, float, etc E.g age = int(input()) #to make the input an integer#
7th Jun 2022, 10:17 AM
Ahmeed Etti Balogun
Ahmeed Etti Balogun - avatar
+ 2
Python is a very reliable language. We can give string, integer & float to the input function.
24th Apr 2022, 2:58 PM
Muhammad Rehan
Muhammad Rehan - avatar
+ 2
If you want integer Use int(input())
7th Jul 2022, 4:42 PM
Cherry
Cherry - avatar
+ 1
input() normally returns a strings. However , you can change it to another type by converting it to the desired type such as float, int ,....
11th Jul 2021, 9:06 AM
Saman RK M.D.
Saman RK M.D. - avatar
+ 1
Because in python input default set to string. If we want to take input in any other data type then we have to write the data type name before the input().
15th Oct 2021, 3:38 AM
Shivam Sahu
Shivam Sahu - avatar
+ 1
input() always returns a string but you can change the type of output. For example if you want an integer type write int(input())
18th May 2022, 3:53 PM
Jyoti Gupta
+ 1
age=input () print =(age)
20th Oct 2022, 12:18 PM
Daniel Chikezie
Daniel Chikezie - avatar
0
but even if you output a number x and then calculate type (x) it's going to say that it's a string
4th Feb 2018, 7:57 PM
Maria Leonor
0
thank you! 😊
5th Feb 2018, 1:03 AM
Maria Leonor
0
That is how the python language is.nl
30th Jun 2021, 10:18 PM
Abdulsamad
0
You can declare the type of input you want in other to simplify your coding and better understanding for other users. Output can be float, string, int and Boolean if the declaration is specified.
22nd Aug 2021, 8:36 PM
Atanda Waheed Olaide
Atanda Waheed Olaide - avatar
0
Anyone good in python to put me through as a mentor please . my WhatsApp +2347015461644
24th Sep 2021, 7:50 AM
Hussein Abubakar
Hussein Abubakar - avatar
0
Input("Enter any year: ") How to get year to be read as an integer?
31st Oct 2021, 6:08 AM
Sebastien Brady
Sebastien Brady - avatar
0
The output for an input returns always a string value
22nd Feb 2022, 9:03 PM
Daniel Yeboah
0
When you enter a character string, the 'ENTER' key signifies an end of line. The input function will read each character entered and save them in the variable until it encounters the end of line character.
8th May 2022, 1:41 PM
Radouane
Radouane - avatar
0
By default it's string but you can change if you want, to either float, int etc
17th May 2022, 11:52 AM
mr khan
mr khan - avatar
0
Default value
6th Jul 2022, 9:15 PM
Ly5555
Ly5555 - avatar