Font size
S
M
L
XL
WorksheetsPython Advanced
Total questions: 100
Worksheet time: 1hrs 19mins
Name
Class
Date
1.
Which keyword starts a class definition in Python?
a)
def
b)
class
c)
struct
d)
module
2.
Which method is automatically invoked when a new instance is created?
a)
__new__
b)
__call__
c)
__init__
d)
__start__
3.
What does the 'self' parameter in instance methods refer to?
a)
Current class
b)
Instance object
c)
Parent class
d)
Global namespace
4.
Which of these is an example of encapsulation?
a)
Using global variables
b)
Hiding attributes using name-mangling
c)
Multiple inheritance
d)
Using map/filter
5.
How do you indicate a 'private' attribute by convention in Python?
a)
prefix with __
b)
suffix with _priv
c)
prefix with _
d)
use private keyword
6.
What is name mangling in Python?
a)
Encrypting names
b)
Compiler optimization
c)
Interpreter renaming __attr to _ClassName__attr
d)
Renaming modules
7.
Which decorator defines a class method that receives the class instead of instance?
a)
@staticmethod
b)
@classmethod
c)
@property
d)
@abstractmethod
8.
Which decorator creates a method that does not receive instance or class automatically?
a)
@staticmethod
b)
@classmethod
c)
@instancemethod
d)
@bind
9.
What is method overriding?
a)
Providing multiple methods of same name in same class
b)
Redefining parent method in subclass
c)
Using same name for variables
d)
Calling a method twice
10.
Which built-in checks whether an object is an instance of a class or tuple of classes?
a)
type()
b)
isinstance()
c)
issubclass()
d)
hasattr()
11.
Which of the following best describes polymorphism in Python?
a)
Single form only
b)
Different objects responding to same interface
c)
Only inheritance used
d)
Data hiding technique
12.
In multiple inheritance, what does MRO determine?
a)
Method parameter order
b)
Order in which base classes are searched for methods
c)
Order of attribute creation
d)
Order of imports
13.
Which function returns the MRO of a class?
a)
mro()
b)
getmro()
c)
class_mro()
d)
resolve_mro()
14.
What is a mixin class typically used for?
a)
Full standalone application
b)
Providing small reusable functionality to classes
c)
Replacing multiple inheritance
d)
Compiling code
15.
Which module provides Abstract Base Classes support in Python?
a)
abc
b)
abstract
c)
base
d)
interface
16.
How do you declare an abstract method in Python?
a)
@abstract
b)
@abstractmethod
c)
@absmethod
d)
declare abstract
17.
Which dunder method should you implement for a readable informal string of an object?
a)
__repr__
b)
__str__
c)
__format__
d)
__display__
18.
What happens if a subclass does not implement an abstract method?
a)
Class is instantiable
b)
Subclass becomes abstract and cannot be instantiated
c)
Method is removed
d)
Runtime error when defining class
19.
Which of these is true about private variables prefixed with double underscore?
a)
They are truly private and inaccessible
b)
They are name-mangled but still accessible by mangled name
c)
They are public
d)
They are only used by interpreter
20.
When using super() in a cooperative multiple-inheritance pattern, what should methods do?
a)
Ignore super()
b)
Call super() to continue the chain
c)
Call only base class directly
d)
Use global functions
21.
Which GUI toolkit is included with the standard Python distribution?
a)
PyQt
b)
Tkinter
c)
Kivy
d)
WxPython
22.
Which layout managers does Tkinter provide?
a)
pack, grid, place
b)
flow, grid, anchor
c)
dock, float, pack
d)
pack, flow, table
23.
Which widget is appropriate for multi-line editable text in Tkinter?
a)
Entry
b)
Text
c)
Label
d)
Spinbox
24.
Which object represents the main application window in Tkinter?
a)
Tk() instance
b)
Frame
c)
Toplevel only
d)
MainWindow class
25.
Which method is used to register an event handler for a widget in Tkinter?
a)
on()
b)
bind()
c)
attach()
d)
connect()
26.
Which GUI framework uses the Qt libraries and supports designer tools?
a)
Tkinter
b)
Kivy
c)
PyQt
d)
Pygame
27.
Which file format does Kivy use to declare UI in a declarative way?
a)
kv file
b)
ui.xml
c)
kivy.json
d)
layout.k
28.
What is the purpose of the mainloop() in GUI apps?
a)
Compile code
b)
Enter event loop to handle events
c)
Run unit tests
d)
Optimize rendering
29.
Which widget is used to create a clickable button in Tkinter?
a)
Label
b)
Canvas
c)
Button
d)
Scale
30.
Which PyQt method starts the event loop?
a)
app.execute()
b)
app.exec_()
c)
app.run()
d)
app.start()
31.
Which of these is a common issue when running blocking tasks in the GUI main thread?
a)
Faster response
b)
UI freeze
c)
Automatic scaling
d)
Background updates
32.
Which Python module is commonly used for embedding SQLite access in desktop apps?
a)
sqlite3
b)
pyodbc
c)
psycopg2
d)
pymongo
33.
Which technique is recommended to update the GUI from a background thread?
a)
Direct widget modification from thread
b)
Use thread-safe queues and schedule update on main thread
c)
Kill main thread
d)
Use print statements
34.
Which packaging tool is commonly used to create standalone desktop executables for Python apps?
a)
pip
b)
conda
c)
PyInstaller
d)
virtualenv
35.
Which widget would you use in Tkinter to show selectable options in a drop-down?
a)
Listbox
b)
Combobox (ttk)
c)
Button
d)
Scale
36.
What mechanism allows a GUI to remain responsive while performing I/O?
a)
Busy-wait loops
b)
Background threads or asynchronous I/O
c)
Blocking calls in mainloop
d)
Recursive loops
37.
Which PyQt concept connects signals to slots?
a)
Event binding
b)
Signal-slot mechanism
c)
Callback registry
d)
Listener map
38.
Which Tkinter method schedules a callback after given milliseconds?
a)
schedule()
b)
after()
c)
delay()
d)
settimeout()
39.
Which approach is best for creating a file manager UI using PyQt?
a)
Use raw sockets
b)
Leverage QFileSystemModel and views
c)
Embed web browser
d)
Use Tkinter widgets
40.
When distributing a PyQt application, which license consideration may be important?
a)
GPL/LGPL licensing for Qt
b)
Python license
c)
MIT license only
d)
No licenses matter
41.
Which framework emphasizes speed and pydantic-based data validation for APIs?
a)
Django
b)
Flask
c)
FastAPI
d)
Bottle
42.
Which Flask function decorator maps a URL to a view function?
a)
@app.route()
b)
@app.url()
c)
@route.path()
d)
@flask.map()
43.
Which HTTP methods are typically used for CRUD create and delete respectively?
a)
GET and POST
b)
POST and DELETE
c)
PUT and GET
d)
PATCH and OPTIONS
44.
Which header or token mechanism is commonly used with JWTs for authentication?
a)
Cookie only
b)
Authorization header with Bearer token
c)
Referer header
d)
ETag
45.
Which library is commonly used with Flask for handling JWTs?
a)
flask-jwt-extended
b)
django-jwt
c)
pyjwt-generic
d)
jwtflask
46.
What is the purpose of WebSockets in web applications?
a)
Static pages only
b)
Real-time bidirectional communication
c)
Compress responses
d)
Authenticate users
47.
Which function in FastAPI declares response model types and performs validation?
a)
Depends()
b)
Body()
c)
Query()
d)
The function's return annotation with Pydantic model
48.
Which ASGI server is commonly used to serve FastAPI apps in production?
a)
uWSGI
b)
Gunicorn only
c)
uvicorn
d)
mod_wsgi
49.
What is a major difference between Flask and FastAPI?
a)
Flask is async-first
b)
FastAPI provides automatic API docs and async support
c)
Flask enforces typing
d)
FastAPI uses templates only
50.
Which protocol does WebSocket use after initial HTTP handshake?
a)
Continued HTTP
b)
UDP
c)
WS over TCP (upgraded connection)
d)
FTP
51.
Which status code represents successful creation of a resource?
a)
200 OK
b)
201 Created
c)
204 No Content
d)
403 Forbidden
52.
Which FastAPI feature automatically generates interactive API docs?
a)
Flask-Docs
b)
Swagger UI / Redoc via OpenAPI
c)
Sphinx
d)
Django Admin
53.
Which method improves throughput by allowing handlers to do non-blocking I/O in FastAPI?
a)
Synchronous functions only
b)
Using async def and await
c)
Thread.sleep
d)
Using global variables
54.
Which technique helps protect against Cross-Site Request Forgery (CSRF) in web apps?
a)
Use only GET requests
b)
CSRF tokens on state-changing forms
c)
Disable cookies
d)
Use TLS only
55.
What mechanism is commonly used to paginate large query results in REST APIs?
a)
Return everything
b)
Offset and limit parameters
c)
Use FTP
d)
Embed images only
56.
How would you secure sensitive configuration (like DB credentials) in a web app?
a)
Hardcode in source
b)
Store in environment variables or secret manager
c)
Commit to repo
d)
Print on logs
57.
Which status code signals that authentication is required or has failed?
a)
200
b)
401 Unauthorized
c)
404 Not Found
d)
302 Found
58.
Which library helps manage CORS headers in Flask apps?
a)
flask-cors
b)
flask-headers
c)
flask-security
d)
flask-auth
59.
When designing RESTful APIs, which HTTP verb is idempotent for updating a resource?
a)
POST
b)
PUT
c)
PATCH
d)
DELETE
60.
Which approach helps scale WebSocket servers horizontally?
a)
Single process only
b)
Using message brokers and shared pub/sub (e.g., Redis)
c)
Storing all state in local memory
d)
Avoiding load balancers
61.
Which library is most commonly used for data manipulation in Python?
a)
NumPy
b)
Pandas
c)
Matplotlib
d)
Requests
62.
Which function splits data into training and test sets in scikit-learn?
a)
train_test_split
b)
split_data
c)
data_slice
d)
train_split
63.
What is the primary purpose of cross-validation?
a)
Increase training size only
b)
Estimate model generalization performance
c)
Encrypt data
d)
Speed up training
64.
Which metric is appropriate for binary classification with imbalanced classes?
a)
Accuracy
b)
Precision/Recall or F1-score
c)
Mean Squared Error
d)
R^2
65.
Which transformer handles categorical variables by creating integer codes?
a)
OneHotEncoder
b)
LabelEncoder
c)
StandardScaler
d)
Imputer
66.
Why is feature scaling often important for algorithms like KNN and SVM?
a)
It isn't important
b)
To make features comparable and avoid dominance by scale
c)
To reduce dataset size
d)
To convert to integers
67.
Which object in scikit-learn serializes a trained model to disk?
a)
pickle or joblib
b)
save_model() built-in
c)
model.save() always
d)
export()
68.
What is the role of a preprocessing pipeline?
a)
Perform only feature selection
b)
Chain preprocessing steps to apply consistently
c)
Replace model
d)
Generate random features
69.
Which technique helps handle missing values in numerical columns?
a)
Drop entirely
b)
Imputation with mean/median or model-based imputation
c)
Convert to strings
d)
Leave as NaN always
70.
Which algorithm is suitable for a simple interpretable classification baseline?
a)
Random Forest
b)
Decision Tree or Logistic Regression
c)
Deep neural network
d)
K-means
71.
What does overfitting refer to?
a)
Model performs poorly on training data
b)
Model memorizes training data and performs poorly on unseen data
c)
Perfect generalization
d)
Faster training
72.
Which method estimates hyperparameters by searching over parameter grid with cross-validation?
a)
GridSearchCV
b)
RandomForest
c)
PCA
d)
GradientBoost
73.
Which library provides efficient array operations used across ML code?
a)
Pandas
b)
NumPy
c)
Requests
d)
Flask
74.
Why serialize both preprocessing and model together for deployment?
a)
Only model matters
b)
To ensure same preprocessing used at inference time
c)
To reduce file size
d)
To avoid licensing
75.
Which metric measures the average squared difference between predicted and actual values in regression?
a)
MAE
b)
MSE
c)
Accuracy
d)
AUC
76.
What is the train/test split purpose?
a)
To tune hyperparameters only
b)
To evaluate generalization performance on held-out data
c)
To augment data
d)
To change labels
77.
Which method reduces dimensionality while preserving variance by projecting onto principal components?
a)
t-SNE
b)
PCA
c)
LDA
d)
UMAP
78.
What is data leakage in ML pipelines?
a)
Data shared between training and test sets leading to overly optimistic performance
b)
Encrypting data
c)
Using too much RAM
d)
Incorrect feature scaling
79.
Which resampling technique balances classes by generating synthetic examples?
a)
Undersampling
b)
Oversampling (SMOTE)
c)
Cross-validation
d)
Bootstrap
80.
Which file format is commonly used to store serialized scikit-learn pipelines?
a)
.exe
b)
.joblib or .pkl
c)
.html
d)
.sql
81.
Which framework is primarily used for building and training deep neural networks?
a)
Scikit-learn
b)
TensorFlow
c)
Flask
d)
Qt
82.
Which lightweight library is often used for building ML models and quick prototypes?
a)
TensorFlow
b)
PyTorch
c)
Scikit-learn
d)
Pygame
83.
Which deployment pattern wraps ML model inference into an HTTP endpoint?
a)
Desktop app only
b)
Serving via REST API (Flask/FastAPI)
c)
Use FTP
d)
CLI only
84.
What is model monitoring after deployment primarily used for?
a)
Only logging
b)
Detecting data drift and model performance degradation
c)
To retrain automatically always
d)
To encrypt models
85.
Which tool helps convert a PyTorch model to a format optimized for mobile or production (example)?
a)
joblib
b)
ONNX
c)
csv
d)
sql
86.
Which architecture component helps queue and manage inference requests for scale?
a)
Single-threaded loop
b)
Message queues / model server with worker pool
c)
Hard-coded concurrency
d)
Local files only
87.
Which technique can be used to reduce model size and latency for deployment?
a)
Model quantization or pruning
b)
Adding layers
c)
Increasing batch size
d)
Using Python only
88.
Which of these enables conversational automation using AI?
a)
Scripting only
b)
Chatbot frameworks with NLU backends
c)
Manual email replies
d)
Static websites
89.
Which library is commonly used for building chatbots and conversational assistants rapidly?
a)
RDBMS
b)
Rasa
c)
Pygame
d)
PyQt
90.
Which method allows A/B testing of different model versions in production?
a)
Deploy single version only
b)
Use feature flags or routing and traffic-splitting
c)
Manual switching
d)
No A/B testing
91.
When automating pipelines, which tool helps orchestrate workflows and dependencies?
a)
cron only
b)
Airflow or similar DAG orchestrators
c)
manual scripts
d)
notebooks only
92.
Which practice secures model APIs in production?
a)
Expose endpoints publicly
b)
Require authentication and use TLS
c)
Send tokens in URL
d)
Use plain HTTP
93.
Which approach helps serve low-latency predictions for real-time systems?
a)
Batch-only inference
b)
Using optimized model servers or in-memory serving (e.g., TensorRT)
c)
Run training at inference
d)
Use spreadsheets
94.
Which monitoring signals indicate data drift in production?
a)
Unchanged input distributions
b)
Shift in feature distributions or input statistics
c)
Faster response times
d)
Higher CPU usage only
95.
What is transfer learning useful for?
a)
Training from scratch always
b)
Reusing pretrained models to reduce data and time
c)
Avoiding models
d)
Only for regression
96.
Which format is commonly used to serialize TensorFlow models for serving?
a)
.pkl
b)
.h5 or SavedModel format
c)
.txt
d)
.csv
97.
Which cloud-native approach helps autoscale model serving based on load?
a)
Fixed-size VMs only
b)
Kubernetes with autoscaling (HPA)
c)
Manual scaling
d)
Run on laptop
98.
Which concept helps preserve reproducibility for ML experiments and models?
a)
Random seeds, environment capture, and artifact versioning
b)
Only saving final model
c)
Relying on default settings
d)
No documentation
99.
Which tool helps build REST APIs quickly for model inference and supports async for performance?
a)
Flask only
b)
FastAPI
c)
Tkinter
d)
PyQt
100.
Which evaluation approach helps verify model fairness and bias after deployment?
a)
Ignore fairness
b)
Run fairness metrics and checks across groups
c)
Only check accuracy overall
d)
Only check speed
Reset
