CBSE Class XII: Python Data File Handling| seek() and tell()

Example:1
Example of seek() and tell()

we have a file names “test.txt” with contents as

hello how are you
hope all is fine
bye

#seek() and tell()
f=open("test.txt","r")
x=f.tell()
print(x)

Output:

0

Example:2
Example of seek() and tell()

f=open("test.txt","r")
#1
x=f.tell()
print(x)
print(f.read())
#2
f.seek(6)
x=f.tell()
print(x)
print(f.read())

Output:

0
hello how are you
hope all is fine
bye

6
how are you
hope all is fine
bye