Mixed Deck — All PCAP Topics Flashcards
100 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 20 Mixed Deck — All PCAP Topics flashcards as text
What does `str.strip()` do?
Answer: Removes leading and trailing whitespace
`strip()` removes whitespace (or specified characters) from both ends of the string.
How do you check if a key exists in a dictionary?
Answer: if key in dict:
The in keyword is used to check if a key exists in a dictionary
Which exception is raised when accessing an index that does not exist in a list?
Answer: IndexError
`IndexError` is raised when a sequence subscript is out of range.
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.
What is a decorator in Python?
Answer: A function that wraps another function to add behavior
A decorator is a callable that takes a function and returns a new function with added behavior.
What does the `zip()` function do?
Answer: Combines multiple iterables element-by-element into tuples
`zip()` pairs elements from multiple iterables into tuples, stopping at the shortest iterable.
What does the `__name__ == '__main__'` guard do?
Answer: Prevents code from running when the module is imported
Code under `if __name__ == '__main__':` runs only when the script is executed directly, not when imported.
Which exception is raised when you try to open a file that does not exist?
Answer: FileNotFoundError
`FileNotFoundError` is a subclass of `OSError` raised when a file or directory is not found.
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.
What is encapsulation in object-oriented programming?
Answer: Bundling data and methods within a class
Encapsulation bundles data (attributes) and behavior (methods) together inside a class.
How do you raise a custom exception in Python?
Answer: raise Exception('msg')
Python uses the `raise` keyword to manually throw an exception.
What does `**kwargs` allow in a function definition?
Answer: Variable keyword arguments as a dictionary
`**kwargs` collects extra keyword arguments into a dictionary inside the function.
What does `all(iterable)` return if the iterable is empty?
Answer: True
`all([])` returns True by vacuous truth — there are no False elements in an empty sequence.
Which attribute of a function object holds the variables captured by its closure?
Answer: __closure__
`func.__closure__` is a tuple of cell objects, each holding the value of one variable captured from the enclosing scope.
How do you start a comment in Python?
Answer: B) #
In Python, comments are started with the # symbol.
What does the `super()` function do in Python?
Answer: Calls a method from the parent class
`super()` returns a proxy object that delegates method calls to the parent class.
What does `random.randint(1, 10)` return?
Answer: A random integer from 1 to 10 inclusive
`random.randint(a, b)` returns a random integer N such that a <= N <= b (both endpoints included).
What does the following code print?
Answer: 12
The range(3) function generates numbers from 0 to 2, and the for loop prints each number in this range.
Which of the following is used to define a function in Python?
Answer: def
The def keyword is used to define a function in Python.
How do you add a condition to a list comprehension to include only even numbers?
Answer: [x for x in range(10) if x%2==0]
A conditional list comprehension uses `if condition` at the end: `[x for x in iterable if condition]`.
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
- pythoninstitute.org — Eligibility, fees, exam format, passing score, retake fee, retake policy, score release, time limit, score validity, exam information · verified Oct 2026
- home.pearsonvue.com — Test delivery · verified Oct 2026