Issue
Please explain how the readline() method is different from the readlines()
f = open("demofile.txt", "r")
print(f.readline())
print(f.readline())
Solution
The readline method reads one line from the file and returns it as a string. The string returned by readline will contain the newline character at the end. The readlines method returns the contents of the entire file as a list of strings, where each item in the list represents one line of the file.
Answered By - jengelbells Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.