PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] Why does the next line get printed when I call readline() multiple times instead of printing the first line

 August 17, 2022     input, output, python     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing