Skip to content

Installing Python

  • Install Python from the official website: python.org.
  • Use Command Prompt, Git Bash, or Windows PowerShell to run Python commands.
  • Install a terminal if not already available.

Principles of Python

  • Clean → Write code that is simple and uncluttered.
  • Readability → Make code easy to understand for yourself and others.
  • Predictability → Ensure consistent behavior and avoid surprises.
  • Don’t Repeat Yourself (DRY) → Reuse logic instead of duplicating it.

Organizing Code in Python

Approaches to Organizing Code

  • Functions → Avoid repetition by encapsulating logic.
  • Object-Oriented Programming (OOP) → Create blueprints using classes and objects.
  • Functional Programming (FP) → Use pure functions without side effects.

Paradigm

A paradigm in programming is essentially a style or philosophy of how we think about and organize code. It’s not about syntax, but about the approach we take to solving problems.

Key Programming Paradigms - Procedural Programming → Code is written as step‑by‑step instructions (functions, procedures).
- Object‑Oriented Programming (OOP) → Code is organized around classes and objects, bundling data with behavior.
- Functional Programming → Focuses on pure functions, immutability, and avoiding side effects.
- Declarative Programming → You describe what you want done, not how (e.g., SQL queries).


Terminal Basics

The terminal was the original way humans gave instructions to computers and received output.
Before GUIs (Graphical User Interfaces), all interaction was text-based.
You can use the terminal to access servers, databases, and applications.


Common Commands

  • ls (Linux/Mac) / dir (Windows): List files in the current directory.
  • pwd (Linux/Mac): Show current directory.
  • cd <folder>: Change directory.
  • cd ..: Move one directory up.
  • cd /: Go to root directory.
  • cd ~: Go to home directory.
  • cd "My Folder" or cd My\ Folder: Access folders with spaces in names.
  • explorer . (Windows): Open current directory in File Explorer.
  • start . (Windows): Same as above.

File & Folder Management

  • mkdir folder_name: Create a new folder.
  • rmdir folder_name: Delete an empty folder.
  • echo > file_name.html (Windows): Create a new file.
  • del file_name (Windows): Delete a file.
  • Remove-Item filename.txt (PowerShell): Delete a file.
  • New-Item index.html (PowerShell): Create a new file.
  • ren old_name new_name (PowerShell): Rename a file or folder.
  • Remove-Item webapp -Recurse -Force (PowerShell): Delete a folder and all its contents.

Process Control

  • ctrl + c: Stop the current process.
  • ctrl + z: Pause the current process.

Productivity

  • tab: Auto-complete command or file/folder name.
  • start index.html: Open file in default application (Windows).
  • code index.html: Open file in VS Code.

VS Code Terminal

  • Run Python files directly:
  python filename.py

PEP 8 (Python Enhancement Proposal)

  • A set of guidelines and best practices for writing clean Python code.
  • Install the autopep8 extension in VS Code to format code automatically.

Jupyter Notebook

  • An open-source web application for interactive coding.
  • File extension: .ipynb (Interactive Python Notebook).
  • Shortcut to run a cell: Shift + Enter.
  • Widely used in data science, machine learning, and visualization.

Additional Useful Commands

Linux/Mac Specific - touch file.txt: Create a new empty file. - rm file.txt: Delete a file. - rm -r folder_name: Delete a folder and its contents. - cat file.txt: Display file contents. - nano file.txt: Edit file in terminal. - history: Show command history. - man : Show manual/help for a command.


Git Bash / Git

  • git init: Initialize a repository.
  • git clone : Clone a repository.
  • git status: Show changes.
  • git add .: Stage changes.
  • git commit -m "message": Commit changes.
  • git push: Push changes to remote.

Virtual Environments

  • Allow different projects to use different package versions.

pipenv Allows pip and virtual env to install packages based on each project.

Pycharm has built in virtual environment support.
Any library that is installed will have its own Package right in here so it doesn't affect any other projects.

See versions in pyvenv.cfg

Semantic Versioning:

  • Versioning in python is done through semantic versioning.

This is a standard way of numbering software versions:

MAJOR → Big changes that break backward compatibility. Example: 2.0.0 (a rewrite that makes old code incompatible). MINOR → New features added, but still backward compatible. Example: 2.1.0 (adds a new function, but old code still works). PATCH → Bug fixes or small improvements, backward compatible. Example: 2.1.1 (fixes a bug without changing features).

MAJOR.MINOR.PATCH