what is the difference between read() and readlines()? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what is the difference between read() and readlines()?

10th Oct 2018, 4:14 PM
sama baluom
sama baluom - avatar
4 Answers
+ 2
Read method reads the whole file as a single string while readlines segregates each of the line in the file and you then can later on call them line by line.
10th Oct 2018, 4:28 PM
Hamid Ashraf
Hamid Ashraf - avatar
0
Hamid Ashraf what if i used readline first then i used read()? will read() read all file include first line?
10th Oct 2018, 4:41 PM
sama baluom
sama baluom - avatar
0
That depends on your code. If f is an open file you can apply any method in any sequence provided that you are saving their output in different variable.
10th Oct 2018, 5:02 PM
Hamid Ashraf
Hamid Ashraf - avatar
0
Hamid Ashraf thank you :)
10th Oct 2018, 5:04 PM
sama baluom
sama baluom - avatar