Open In App

fileinput.isfirstline() in Python

Last Updated : 22 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
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 - Python3 1=1
# import fileinput
import fileinput

# Using fileinput.isfirstline() method
for line in fileinput.input(files ='gfg.txt'):
    print(fileinput.isfirstline())
Output :   Example #2 : Input Files - Python3 1=1
# import fileinput
import fileinput

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

Next Article
Practice Tags :

Similar Reads