Difference between input () and readline () functions in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between input () and readline () functions in python

Guys can anyone explain the difference between input () and readline () in python with a simple example

31st Jan 2023, 6:47 AM
Kabilan K
Kabilan K - avatar
12 Answers
+ 3
I was confused for the same reason like Lothar. One difference is that readline reads escape sequences, for example, a newline will also be saved in a variable. https://code.sololearn.com/ct832uf2Quf0/?ref=app Another difference is the arugment for input is used as the prompt message when readline takes an integer and reads that many characters from the input stream. But it probably is not what making the difference in you case.
31st Jan 2023, 7:35 AM
Lochard
Lochard - avatar
+ 13
Kabilan K , > input() function is to take an input from the user (done in the console) *[edit]*: input can have a prompt to the user that is shown when input is executed. > readline() is a method of a file object (reading one line from a file that has been opend with open(<filename>, <filemode>)) *[edit]*: no user prompt possible.
31st Jan 2023, 7:04 AM
Lothar
Lothar - avatar
+ 12
Kabilan K , it is always a good idea to share all required information with question... > stdin from sys module does also use method named readline()
31st Jan 2023, 7:16 AM
Lothar
Lothar - avatar
+ 4
Alex Wairegi Lochard codebit is correct. did you enter the inputs correctly? (the format that sololearn follows, providing all the inputs that a program needs on separate line)
2nd Feb 2023, 5:57 PM
Sandeep
Sandeep - avatar
+ 4
Sandeep ooh I see my mistake😅😅
2nd Feb 2023, 7:46 PM
Alex Wairegi
Alex Wairegi - avatar
+ 3
I see that you have completed a lot of courses. May I ask what have you confused? Because their use cases seem very different to me.
31st Jan 2023, 6:57 AM
Lochard
Lochard - avatar
+ 3
Alex Wairegi i think you should try again because it is not giving me any error. i am entering all three inputs on separate line
2nd Feb 2023, 6:10 PM
Sandeep
Sandeep - avatar
+ 2
Yesterday i solved a coding challenge in that if i use the input () function one test case didn't get passed but the readline() get passed on all the test cases
31st Jan 2023, 6:59 AM
Kabilan K
Kabilan K - avatar
+ 2
Sandeep yes it gave me the EOF EXCEPTION
2nd Feb 2023, 6:04 PM
Alex Wairegi
Alex Wairegi - avatar
+ 1
Lothar but in a coding challenge i just used it as " data=sys.stdin.readline() " so how here the function works
31st Jan 2023, 7:07 AM
Kabilan K
Kabilan K - avatar
+ 1
Lothar so how does that function get input from the user i mean until?
31st Jan 2023, 7:18 AM
Kabilan K
Kabilan K - avatar