In the package layout below, which file marks `mypkg` as a regular Python package? mypkg/ __init__.py utils.py
Pcap Modules Packages Category
Question · Easy
What does this snippet print when run as the main script? if __name__ == '__main__': print('main') else: print('imported')
Chapter 1: The PCAP-31-03 Exam Blueprint and Test-Day Logistics
1.1 The PCAP-31-03 Blueprint, Scoring, and Exam-Day Logistics
Study guide
Which import style triggers a circular import only at the module-load time?
Question · Hard
Tech Exam Prep Podcast
Listen on Spotify
Podcast
Which standard library module would you use to generate cryptographically secure random tokens?
Question · Medium
What does this code print? import math print(math.floor(-2.3), math.ceil(-2.3))
What does the following snippet output? import platform print(type(platform.python_version()).__name__)
Chapter 2: Modules, Packages, and the Standard Library
2.1 Module Imports and Namespace Mechanics
Which statement is TRUE about the Python exception hierarchy?
Pcap Exceptions Category
What does this code print? try: raise ValueError('a') except ArithmeticError: print('arith') except Exception: print('exc')
What does this code print? class MyError(Exception): pass try: raise MyError('boom') except MyError as e: print(e)
What does this snippet output? try: try: raise ValueError('inner') except ValueError: raise TypeError('outer') except TypeError as e: print(e, e.__context__)
2.2 Module Construction and Execution
What does this code output? try: try: raise ValueError('a') except ValueError as e: raise RuntimeError('b') from e except RuntimeError as e: print(e.__cause__)
What does this code print? try: x = 1 / 0 except ArithmeticError: print('arith') finally: print('done')
What does this snippet print? print(ord('A'), chr(97))
Pcap Strings Category
What does the following code print? s = 'Hello, World!' print(s.lower(), s)
2.3 Package Hierarchy and Navigation
What does this code output? s = 'python' print(s.title(), s.capitalize())
What does this code print? s = 'aaa,bbb,ccc' print(s.split(',', 1))
What does this code output? s = 'abracadabra' print(s.find('cad'), s.find('xyz'))
What does this code print? s = 'Python3.12' print(s.isalpha(), s.isalnum())
2.4 Standard Library Modules and Pip
What is the value of the following expression? 'Hello'.encode('utf-8')
What does the following snippet print? class A: def __init__(self, x): self.x = x a = A(5) print(a.x)
Pcap Oop Category
What does this code print? class A: count = 0 def __init__(self): A.count += 1 a = A() b = A() print(A.count)
What does this code output? class A: def __init__(self): self.__x = 10 a = A() print(a._A__x)
Chapter 3: Exceptions and Error Handling
3.1 Exception Control Flow and Syntax
What does this code print? class A: def __str__(self): return 'A-str' def __repr__(self): return 'A-repr' a = A() print(a) print([a])
What does this code output? class A: def __init__(self, v): self.v = v def __eq__(self, other): return self.v == other.v a1 = A(10) a2 = A(10) print(a1 == a2)
What does this code print? class A: def f(self): return 'A' class B(A): def f(self): return 'B' b = B() print(b.f())
What does this code output? class A: def f(self): return 'A' class B(A): def f(self): return 'B-' + super().f() print(B().f())
3.2 The Built-in Exception Hierarchy
What is printed? class A: pass class B(A): pass b = B() print(isinstance(b, A), issubclass(B, A))
What does this code output? class A: def f(self): return 'A' class B: def f(self): return 'B' class C(A, B): pass print(C().f())
What does the following snippet print? class A: @classmethod def info(cls): return cls.__name__ print(A.info())
What does this code print? class A: @staticmethod def add(x, y): return x + y print(A.add(3, 4))
3.3 Raising Exceptions and Assertions
What does this code output? class A: def __init__(self): self._x = 10 @property def x(self): return self._x * 2 a = A() print(a.x)
Which method is called automatically when an object is destroyed (garbage-collected)?
What does this code print? class A: __slots__ = ['x'] a = A() a.x = 1 a.y = 2 print(a.y)
What does this code output? class A: def __init__(self): self.x = 1 self.y = 2 a = A() print(sorted(a.__dict__.keys()))
3.4 Custom Exceptions and Exception Chaining
What does this code print? nums = [x * x for x in range(5) if x % 2 == 0] print(nums)
Pcap Misc Category
What does this code output? d = {x: x * 2 for x in range(3)} print(d)
What does this code print? add = lambda x, y: x + y print(add(3, 4))
What does this code output? nums = [1, 2, 3, 4] result = list(map(lambda x: x * 2, nums)) print(result)
Loading more…