Python Tutorial

Introduction and Setup

Welcome to Python!

What is Python?

Python is a programming language designed for humans, not just computers.

  • Simple and readable syntax - Code looks like English sentences
  • Versatile - Build websites, analyze data, create AI, automate tasks
  • Huge ecosystem - 400,000+ packages for any task imaginable
  • Community-driven - Free, open-source, constantly improving
  • Cross-platform - Write once, run on Windows, Mac, Linux

Why Learn Python?

Popular Fields: - Data Science & AI - Web Development - Automation & Scripting - Scientific Computing - Game Development

Benefits: - Easy to learn - High demand in job market - Active community - Extensive documentation

The Zen of Python

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Readability counts.

import this

Environment Setup

Modern Python Setup with uv

Recommended: Use uv - it handles everything!

# Install uv (handles Python + environments)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# uv automatically installs Python when needed
uv python install 3.12
# Install uv 
curl -LsSf https://astral.sh/uv/install.sh | sh

# uv automatically manages Python versions
uv python install 3.12
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# uv automatically manages Python versions
uv python install 3.12

Why uv?

All-in-one solution: Python + packages + environments ✅ 10-100x faster than pip ✅ Cross-platform - works everywhere ✅ No manual Python installation needed ✅ Industry standard for modern Python development

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create project
uv init my-project
cd my-project

# Add packages
uv add pandas requests

# Run code
uv run python script.py

VS Code Setup 🛠️

Essential Extensions: - Python - Ruff (linting & formatting) - Pyright (type checking) - Error Lens (debugging) - Quarto (for this tutorial!)

Git and GitHub

Why Git?

  • Track changes in your code
  • Collaborate with others
  • Backup your work
  • Version history - never lose code
  • Industry standard for development

Basic Git Workflow

# Initialize repository
git init

# Check status
git status

# Add files
git add filename.py
git add .  # Add all files

# Commit changes
git commit -m "Add new feature"

# View history
git log --oneline

GitHub Integration

# Connect to GitHub
git remote add origin https://github.com/user/repo.git

# Push to GitHub
git push -u origin main

# Pull changes
git pull origin main

Python Basics

Your First Program

print("Hello, Python!")

Output:

Hello, Python!

That’s it! No compilation, no complex setup.

Variables & Types

# Python uses dynamic typing
name = "Alice"          # String
age = 25               # Integer
height = 5.6           # Float
is_student = True      # Boolean

print(f"Name: {name}")
print(f"Age: {age}")
print(f"Height: {height}")
print(f"Student: {is_student}")

String Magic

text = "Python Programming"

# Methods
print(text.upper())         # PYTHON PROGRAMMING
print(text.lower())         # python programming
print(len(text))            # 18

# Slicing
print(text[:6])            # Python
print(text[7:])            # Programming
print(text[::-1])          # gnimmargorP nohtyP

Math Operations

a, b = 10, 3

print(f"{a} + {b} = {a + b}")    # 13
print(f"{a} - {b} = {a - b}")    # 7
print(f"{a} * {b} = {a * b}")    # 30
print(f"{a} / {b} = {a / b}")    # 3.33
print(f"{a} // {b} = {a // b}")  # 3 (floor division)
print(f"{a} % {b} = {a % b}")    # 1 (modulus)
print(f"{a} ** {b} = {a ** b}")  # 1000 (power)

F-String Formatting 🎨

name = "Python"
version = 3.12
popularity = 95.5

# Modern f-string formatting
message = f"Welcome to {name} {version}!"
print(message)

# With formatting
print(f"Popularity: {popularity:.1f}%")
print(f"Padded: {42:05d}")       # 00042
print(f"Aligned: {name:>10}")    # "    Python"

Practice Time!

Exercise: Personal Info

Create variables for your information:

first_name = "Your Name"
last_name = "Your Last Name"
age = 25
city = "Your City"
hobby = "Your Hobby"

# Display nicely formatted
print("=== Personal Information ===")
print(f"Name: {first_name} {last_name}")
print(f"Age: {age} years old")
print(f"City: {city}")
print(f"Hobby: {hobby}")

Exercise: Calculator

num1 = 15
num2 = 4

print(f"Number 1: {num1}")
print(f"Number 2: {num2}")
print("-" * 20)
print(f"Addition: {num1} + {num2} = {num1 + num2}")
print(f"Subtraction: {num1} - {num2} = {num1 - num2}")
print(f"Multiplication: {num1} × {num2} = {num1 * num2}")
print(f"Division: {num1} ÷ {num2} = {num1 / num2:.2f}")

Key Takeaways

  1. Python is readable - code should be clear
  2. Dynamic typing - no need to declare types
  3. F-strings are the best way to format text
  4. Indentation matters - defines code structure
  5. Git early, Git often - version control is essential

What’s Next?

  • Data Types & Collections (lists, dictionaries)
  • Control Flow (if statements, loops)
  • Functions (organizing your code)
  • Object-Oriented Programming
  • Real-world applications

Thank You!

Questions?

Ready to continue with Data Types?

Resources: - Python.org - Real Python - Python Tutor