← All PCAP Flashcard Decks

File I/O and String Operations Flashcards

6 cards from real PCAP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 6 File I/O and String Operations flashcards as text
  1. Which built-in function is used to open a file in Python?

    Answer: open()

    The `open()` function opens a file and returns a file object for reading or writing.

  2. What mode string opens a file for writing, creating it if it does not exist and truncating if it does?

    Answer: 'w'

    Mode `'w'` opens a file for writing, creating it if absent and clearing it if it exists.

  3. What does the `with` statement do when used with `open()`?

    Answer: Automatically closes the file when the block exits

    The `with` statement is a context manager that ensures the file is closed when the block ends, even on exceptions.

  4. Which method reads the entire file content as a single string?

    Answer: read()

    `file.read()` reads the entire file and returns it as a single string.

  5. What does `file.readlines()` return?

    Answer: A list of strings, one per line

    `readlines()` reads all lines and returns them as a list of strings including newline characters.

  6. Which file mode opens a file for appending without truncating existing content?

    Answer: 'a'

    Mode `'a'` opens a file for appending; writes go to the end without erasing existing data.

How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy

Sources & references

Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy

  1. pythoninstitute.org — Eligibility, fees, retake fee, retake policy, score release, time limit, score validity · verified Nov 2026
  2. home.pearsonvue.com — Test delivery · verified Nov 2026