tell() function in Python
Introduction
The tell() function in Python is used to return the current position of the file read/write pointer within the file. An integer value is returned by this method, and it doesn't take any parameter.
The access modes define the file handle position within the file. File handle can be defined as the cursor that defines the position of data to be read/written in the file.
The tell() method is helpful for knowing the position of the File handle.
The current position is retrieved with this method. The initial value of tell() is zero because at initial it points to the starting of the file.
syntax :
file_object.tell()
Considering that 'file.txt' file includes the following text:

Example: Printing the current position.
# Example for demonstrating
# tell() method
# Opening the file
fp = open("C:/Users/Kaushal rajput/Desktop/file.txt", "r")
print ("File name: ", fp.name)
line = fp.readline()
print ("Read Line: %s" % (line))
# priting the current position
pos=fp.tell()
print ("current position: ",pos)
# Close opened file
fo.close()
Output:
Name of the file: C:/Users/Kaushal rajput/Desktop/file.txt
Read Line: Welcome to Tutorial and Example
current position: 33
Example: File Handle position before read/writes to file.
# Example for demonstrating
# tell() method
# Opening the file in read mode
fp = open("C:/Users/Kaushal rajput/Desktop/file.txt", "r")
# Print the position of file handle
print(fp.tell())
#Closing the file
fp.close()
Output :
0
Example: File Handle position after reading data from the file.
# Example for demonstrating
# tell() method
# Opening the file in read mode
fp = open("C:/Users/Kaushal rajput/Desktop/file.txt", "r")
fp.read(8)
# Print the position of file handle
print(fp.tell())
#Closing the file
fp.close()
Output:
'Welcome t'
9
Example: Get the position of a binary file before and after writing to the binary file.
# Example for demonstrating
# tell() method
# Using "wb" in the file mode for reading the binary file
fp = open("bin.txt", "wb")
print(fp.tell())
# Writing to file
fp.write(b'010101011')
print(fp.tell())
# Closing file
fp.close()
Output:
0
9
Conclusion
In the above article, we have learned about the tell() function in Python. We have seen how to use the tell() function for getting the current position of the file read/write pointer within the file.