Courseiva
Exceptions and File I/O →mediumMultiple Choice

PCAP Exceptions and File I/O Practice Question

A file is opened with open('test.txt', 'r'). The file object's tell() method returns 0. After reading 10 characters, what does tell() return?

⚠ Common exam trap

Python Institute often tests the misconception that `tell()` returns the number of characters read or the file size, when in fact it returns the byte offset from the start of the file.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

10

The `tell()` method returns the current position of the file pointer in bytes from the beginning of the file. After reading 10 characters (each being 1 byte in a typical text file), the pointer advances by 10 bytes, so `tell()` returns 10.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    File size

    Why it's wrong here

    File size is irrelevant here because tell() reports the current byte offset from the beginning of the stream, not the total length of the file. If the file is larger than the 10 bytes already read, tell() returns 10 while the file's size in bytes remains larger. File size is obtained with os.path.getsize() or by seeking to the end and calling tell(), not by the position of the cursor after a read.

  • ✗

    0

    Why it's wrong here

    A return value of 0 would mean the file position is still at the very start, but the read operation has already consumed 10 bytes and advanced the cursor forward by exactly that amount. In Python, tell() returns the absolute offset from the beginning of the file, so after reading 10 bytes the position cannot be 0. This option confuses the initial position before any I/O operation with the position after the read.

  • ✗

    -1

    Why it's wrong here

    -1 is never a valid return value from tell() because the method always returns a non-negative integer representing the current offset. Some APIs use -1 to indicate an error or end-of-file condition, but Python's file object uses tell() only to report the actual position, and if the method fails it raises an OSError instead of returning -1. Therefore, -1 cannot be the current position after reading 10 bytes or under any normal circumstances.

  • ✓

    10

    Why this is correct

    After reading 10 bytes (or characters, in text mode on most platforms) from the beginning of the file, the file pointer has advanced from offset 0 to offset 10. Calling tell() immediately after the read returns 10, which correctly reflects that new position in the stream. This is why 10 is the accurate answer: tell() always mirrors the exact number of bytes the read operation has consumed from the start.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.