What does this code do? from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def speak(self): pass a = Animal()
Pcpp1 Advanced Oop Category
Question · Medium
What does this code print? from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Square(Shape): def __init__(self, s): self.s = s def area(self): return self.s ** 2 print(Square(4).area())
Question · Easy
What does this code output? class A: def f(self): return 'A' class B(A): def f(self): return 'B' class C(A): def f(self): return 'C' class D(B, C): pass print(D().f(), D.__mro__[1].__name__)
Question · Hard
Tech Exam Prep Podcast
Listen on Spotify
Podcast
What is a 'mixin' class in Python?
What does this code print? class A: def __getattr__(self, name): return f'no {name}' a = A() a.x = 5 print(a.x, a.y)
How does `__getattribute__` differ from `__getattr__`?
What does this code print? class Desc: def __get__(self, obj, objtype): return 'descriptor' class A: x = Desc() print(A().x)
What is a metaclass in Python?
What does this code print? class Meta(type): def __new__(mcs, name, bases, ns): ns['marked'] = True return super().__new__(mcs, name, bases, ns) class A(metaclass=Meta): pass print(A.marked)
In Python, what is the difference between __new__ and __init__?
What design pattern ensures only one instance of a class exists?
What design pattern lets you swap algorithms at runtime via a common interface?
Which design pattern notifies many dependent objects when one object changes state?
Which design pattern wraps an object to add new behavior without subclassing?
Which design pattern makes incompatible interfaces work together?
Which design pattern centralizes object creation logic?
What does this code do? from contextlib import suppress with suppress(ZeroDivisionError): x = 1 / 0 print('after')
What is the difference between PEP 8 and PEP 257?
Pcpp1 Coding Conventions Category
According to PEP 8, what is the recommended maximum line length?
According to PEP 8, which naming convention applies to a class?
According to PEP 8, what is the recommended order for imports?
What is PEP 20?
What does PEP 484 introduce to Python?
What does this type hint mean? def f(x: int, y: list[str]) -> dict[str, int]: ...
How do you create a virtual environment in Python 3?
What file conventionally lists project dependencies for pip?
What is the modern alternative to setup.py for declaring Python project metadata?
What does this tkinter code do? import tkinter as tk root = tk.Tk() tk.Label(root, text='Hi').pack() root.mainloop()
Pcpp1 Gui Category
Which tkinter geometry manager places widgets in rows and columns?
Which tkinter widget displays a single line of editable text?
What is the purpose of `.bind()` in tkinter?
What is the tkinter `ttk` submodule?
What does `widget.after(1000, callback)` do?
Which tkinter widget allows the user to select from a list of options with a slider/scale?
What does this socket code create? import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Pcpp1 Network Category
What is the correct sequence for a TCP server socket?
What is the key difference between TCP and UDP?
Which Python standard library module fetches a URL and returns the response?
In REST, which HTTP method is conventionally used to update an existing resource (full replacement)?
What does HTTP status code 404 mean?
What does this code do? import json s = json.dumps({'a': 1, 'b': [2, 3]}) print(type(s).__name__)
Pcpp1 File Processing Category
Which json function reads JSON text from a file handle?
What does this code print? import json s = '{"a": 1, "b": null}' d = json.loads(s) print(d['a'], d['b'])
What does this code do? import csv with open('data.csv') as f: reader = csv.reader(f) for row in reader: print(row)
Which csv class lets you read rows as dictionaries keyed by header column names?
Which module parses XML files using a tree-based API in the standard library?
What does this code do? import xml.etree.ElementTree as ET root = ET.fromstring('<a><b>hi</b></a>') print(root.find('b').text)
Loading more…