Python Web Development and Database Fundamentals
Python Development Knowledge Check
Flask Templating and Logic Separation
Q1: Flask Template Purpose
To separate presentation logic from application logic.
- Flask template: HTML with placeholders.
- Jinja2: Templating engine.
- Presentation logic: User Interface (UI).
- Application logic: Backend code.
Note: Separates UI from Python logic.
Python Object-Oriented Programming (OOP)
Q2: Purpose of super()
To call a parent class constructor.
super(): Access parent methods.- Inheritance: Child extends parent.
- Constructor:
__init__.
Note: Use super() in the child __init__.
Q3: Purpose of the @property Decorator
Allows a method to be called like a property.
- Decorator: Modifies a function.
@property: Implements a getter.
Note: Enables attribute-style access.
Python Control Flow
Q4: Purpose of an if Statement
Execute code based on a condition.
- Condition: Evaluates to
TrueorFalse.
Note: Controls decisions in code.
Q5: Keyword for Alternative Condition
elif.
- Chained conditions: Used for multiple branches.
Note: Use for multiple conditional branches.
Q6: Operator to Compare Values
== (Equality operator).
==: Checks for equality.
Note: Do not confuse with = (assignment).
Q7: Function of an else Statement
Executes if no preceding conditions are met.
- Default branch: The fallback execution path.
Note: Runs last.
Python Loops and Iteration
Q8: Example of a Loop
for loop.
- Loop: Repeats a block of code.
Note: Iterates over collections.
Q9: Purpose of while Loop
Repeat execution while a condition remains true.
- Condition loop: Repeats based on a boolean state.
Note: Danger of infinite loops if the condition never becomes false.
Q10: Keyword to Stop a Loop
break.
- Break: Immediately exits the current loop.
Note: Used inside loops.
Q11: Output of for i in range(3)
0 1 2.
range(3): Generates numbers 0, 1, 2.
Note: Range starts at 0 by default.
Q12: Best Loop to Iterate a List
for loop.
- Iteration: The process of repeating over items.
Note: The for loop is built for collections.
Python Data Structures
Q13: Access Value by Key ‘name’
dictionary['name'].
- Dict: Stores key-value pairs.
Note: Keys must match exactly.
Q14: Output of len([1, 3])
2.
len(): Counts the number of items.
Note: The list has two items.
Q15: Method to Add a List Item
append().
- Append: Adds an item to the end of the list.
Note: This is the most common addition method.
Q16: Type Storing Key-Values
Dictionary.
- Mapping: Data structure based on key-value pairs.
Note: Keys must be unique.
Python Classes and OOP Foundation
Q17: Definition of a Class
A blueprint for creating objects.
- Class template: Defines structure and behavior.
Note: The foundation of OOP.
Q18: Creating a Car Instance
car = Car().
- Instance: An object created from a class.
Note: This calls the class constructor.
Q19: Purpose of __init__
To initialize a newly created object.
- Constructor: Sets initial attributes for the object.
Note: Sets initial attributes.
Q20: Concept Inheritance Belongs To
OOP (Object-Oriented Programming).
- Child reuses parent: Promotes code reuse.
Note: Focuses on code reuse.
SQL Database Commands
Q21: SQL Command to Delete Data
DELETE.
- DELETE: Removes rows from a table.
Note: Often paired with a WHERE clause.
Q22: Select All From Students
SELECT * FROM students.
*: Represents all columns.- FROM table: Specifies the target table.
Q23: Command to Change Existing Data
UPDATE.
- UPDATE: Modifies existing rows.
Note: Requires the SET clause.
Q24: Keyword to Filter Records
WHERE.
- Condition filter: Specifies criteria for selection or modification.
Note: Used in SELECT, UPDATE, and DELETE.
Q25: SQL Command to Create a Table
CREATE TABLE.
- DDL: Data Definition Language commands structure.
Note: Defines the database schema.
Q26: Command to Add a Column to a Table
ALTER TABLE.
- ALTER: Modifies the structure of an existing table.
Note: Use with ADD COLUMN.
Q27: Not a Data Type
Loop.
- Loop: A control structure, not a storage type.
Note: Data types store values.
SQLite Database Interaction
Q28: Library for SQLite
sqlite3.
- Built-in: Included with standard Python installations.
Note: No external installation required.
Q29: Connect to an SQLite DB
sqlite3.connect('database.db').
- Connection: Establishes a link to the database file.
Note: Creates the DB file if it does not exist.
Q30: Method to Execute SQL
execute().
- Cursor executes: Sends commands to the database via a cursor object.
Note: Used to run SQL commands.
Q31: Object Used to Interact with DB
Cursor.
- Cursor handles SQL: Manages command execution and result fetching.
Note: Used to fetch query results.
Q32: Save DB Changes
connection.commit().
- Commit saves: Makes changes permanent in the database.
Note: Required for write operations (INSERT, UPDATE, DELETE).
Python Environments and Tools
Q33: What is a Virtual Environment?
A self-contained Python environment.
venv: Isolates project dependencies.
Note: Avoids dependency version conflicts between projects.
Q34: Purpose of a Virtual Environment
To manage project-specific dependencies.
- Dependency: A required package or library.
Note: Dependencies are managed per-project.
Q35: IDE Stands For What?
Integrated Development Environment.
- IDE: Combines an editor, debugger, and tools.
Note: Examples include VS Code and PyCharm.
Flask Web Framework Specifics
Q36: Flask is Used For
Web development.
- Microframework: Provides core routing and templating capabilities.
Note: Focuses on routes and templates.
Q37: Method to Define a Route
@app.route().
- Route: Maps a URL path to a Python function.
Note: This decorator binds the view function to a URL.
Q38: File Extension for Templates
.html.
- HTML markup: Standard structure for web pages.
Note: Jinja syntax is embedded within these HTML files.
Q39: How to Start Flask Dev Server
flask run.
- Dev server: Runs the application locally for testing.
Note: Requires the FLASK_APP environment variable to be set.
Python Operators and Testing
Q40: Test if an Element Exists
The in operator.
- Membership operator: Checks for presence within a collection.
Note: Works on lists, sets, and dictionaries (keys).
Q41: What is Unit Testing?
Testing individual, isolated units of code.
- Unit: The smallest testable piece of software.
Note: Common frameworks include pytest and unittest.
Q42: Purpose of Integration Testing
To test how multiple units work together.
- Integration: Checks the interaction between combined components.
Note: Focuses on interface correctness.
Q43: Black-Box vs White-Box Testing
- Black-box: Tests functionality without knowledge of internal code structure.
- White-box: Tests based on internal logic and code visibility.
Notes: Black-box focuses on behavior; white-box focuses on structure.
Basic Data Types
Q44: Type of 3.14
Float (Floating-point number).
- Float: A numeric type representing decimals.
Note: Used for non-integer numeric values.
Q45: What Boolean Holds
True or False.
- Bool type: Represents logical truth values.
Note: Essential for conditional logic.
Git and Version Control
Q46: Command to Copy a GitHub Repo
git clone.
- Clone: Downloads the entire repository history to a local machine.
Note: Creates a local working copy.
MVC Pattern and Flask Input
Q47: Purpose of venv
To isolate dependencies from the global Python installation.
- Isolation: Keeps project requirements separate.
Note: Avoids version conflicts.
Q48: MVC Component for Business Logic
Model.
- Model: Handles data representation and core business rules.
Note: Contains the core logic.
Q49: Module for CSV Files
csv.
- CSV: Comma-Separated Values format.
Note: Provides reader and writer objects.
Q50: Purpose of Controller in MVC
To handle user input and coordinate the Model and View layers.
- Controller: Acts as the logic glue or mediator between input and data/presentation.
Q51: Flask Object for Form Data
request.form.
- Request: Holds incoming data from the client.
Note: Used primarily for data submitted via POST forms.
Q52: Method Used to Insert New Record
POST.
- POST: Used to send data to the server for creation or submission.
Note: Standard method for form submissions creating new resources.
Q53: Why Server-Side Validation?
Because client-side validation can be easily bypassed by malicious users.
- Validation: The process of checking data integrity.
Note: Backend must always verify input.
Containerization and DevOps
Q54: What is a Docker Container?
A lightweight, isolated environment packaging an application and all its dependencies.
- Container: A packaged, runnable instance of an image.
Note: Ensures consistent behavior across different machines.
Q55: File Defining a Docker Image
Dockerfile.
- Build file: Contains step-by-step instructions for building the image.
Q56: Detached Mode Command
docker run -d.
-d: Runs the container in the background (detached).
Note: Does not block the terminal session.
Q57: Advantage of Docker
It ensures consistent behavior across all deployment systems.
- Consistent environment: Eliminates “it works on my machine” problems.
Q58: Shift-Left Testing Means
Testing activities begin earlier in the Software Development Life Cycle (SDLC).
- Early testing: Finding and fixing defects sooner is cheaper.
Q59: CI/CD Stands For
Continuous Integration / Continuous Delivery (or Deployment).
- CI: Frequent merging of code changes.
- CD: Automation of software release processes.
Note: Focuses on pipeline automation.
Q60: Main Goal of DevSecOps
To integrate security practices throughout the entire DevOps pipeline.
- Security early: Making security an inherent part of development, not an afterthought.
Note: Aims to be secure by design.
