Open In App

fileinput.isfirstline() in Python

Last Updated : 22 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of fileinput.isfirstline() method, we can get the boolean value as True if line read from the file is very first line else false by using fileinput.isfirstline() method.

Syntax : fileinput.isfirstline()

Return : Return True if line read is first line of that file.

Example #1 :
In this example we can see that by using fileinput.isfirstline() method, we are able to get the boolean value as True if line read is very first line from the input file by using this method.

Input File –




# import fileinput
import fileinput
  
# Using fileinput.isfirstline() method
for line in fileinput.input(files ='gfg.txt'):
    print(fileinput.isfirstline())


Output :

 
Example #2 :

Input Files –




# import fileinput
import fileinput
  
# Using fileinput.isfirstline() method
for line in fileinput.input(files =('gfg.txt', 'gfg1.txt')):
    print(fileinput.isfirstline())


Output :


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads