Duration: 5 Hours
📚 Learning Objectives
By the end of this session, you will be able to:
- Understand what programming is and why it matters
- Install Python and set up your development environment
- Write and run your first Python program
- Use the Python REPL for interactive coding
- Understand basic Python syntax and structure
📖 Core Concepts (2 Hours)
What is Programming?
Programming is giving instructions to a computer to solve problems. It's the foundation of all software, automation, and DevOps.
- Instructions: Computers follow step-by-step commands
- Languages: Python, JavaScript, Java, Go, etc.
- Why Python: Simple syntax, powerful libraries, DevOps standard
- DevOps Use: Automation scripts, CI/CD pipelines, infrastructure as code
Why Python for DevOps?
# Python is used in:
# - Automation scripts (Ansible, Fabric)
# - Cloud SDKs (AWS Boto3, Azure SDK)
# - CI/CD tools (Jenkins pipelines)
# - Infrastructure as Code (Pulumi)
# - Monitoring (custom metrics, alerts)
# - Web APIs (Flask, FastAPI)
# 90% of DevOps tools have Python support!
Installing Python
# Check if Python is installed
python3 --version
# or
python --version
# Installation Options:
# Ubuntu/Debian Linux
sudo apt update
sudo apt install python3 python3-pip
# macOS (using Homebrew)
brew install python3
# Windows
# Download from python.org
# Check "Add Python to PATH" during installation
# Verify installation
python3 --version
# Python 3.11.x (or higher)
pip3 --version
# pip 23.x.x
Your First Python Program
# Create a file: hello.py
# The classic first program
print("Hello, World!")
# Print multiple things
print("Welcome to Python!")
print("Let's learn DevOps!")
# Run the program:
# python3 hello.py
Understanding print()
# print() outputs text to the screen
# Basic usage
print("Hello")
# Multiple items
print("Python", "is", "awesome")
# Output: Python is awesome
# With separator
print("2024", "01", "15", sep="-")
# Output: 2024-01-15
# Without newline
print("Loading", end="")
print("...")
# Output: Loading...
# Empty line
print()
The Python REPL
# REPL = Read-Eval-Print-Loop
# Interactive Python shell for testing code
# Start REPL
python3
# You'll see:
# Python 3.11.x
# >>>
# Try these commands:
>>> print("Hello from REPL!")
Hello from REPL!
>>> 2 + 2
4
>>> "Python" * 3
'PythonPythonPython'
>>> len("DevOps")
6
# Exit REPL
>>> exit()
# or Ctrl+D
Comments in Python
# Single line comment - use #
# This is a comment
print("Hello") # This is an inline comment
# Multi-line comments use triple quotes
"""
This is a multi-line comment.
It can span multiple lines.
Great for documentation!
"""
'''
Single quotes also work
for multi-line comments.
'''
# Comments are ignored by Python
# Use them to explain your code!
Python Syntax Basics
# Python uses INDENTATION for code blocks
# No curly braces {} like other languages
# Correct indentation (4 spaces)
if True:
print("This is indented")
print("Same block")
# Wrong indentation causes errors!
# if True:
# print("Error!") # IndentationError!
# Case sensitive
Name = "Alice"
name = "Bob"
# These are DIFFERENT variables!
# Statements end with newline (no semicolons needed)
print("Line 1")
print("Line 2")
🔬 Hands-on Lab (2.5 Hours)
Lab 1: Python Installation
- Install Python 3 on your system
- Verify with
python3 --version - Verify pip with
pip3 --version - Open Python REPL with
python3
Lab 2: REPL Exploration
- Start the Python REPL
- Try basic math:
10 + 5,100 / 4 - Print messages:
print("Your name") - Exit with
exit()
# Lab 2: Practice in REPL
>>> 10 + 5
15
>>> 100 - 25
75
>>> 8 * 7
56
>>> 100 / 4
25.0
>>> 17 // 3 # Integer division
5
>>> 17 % 3 # Remainder (modulo)
2
>>> 2 ** 10 # Power (2^10)
1024
>>> print("I am learning Python!")
I am learning Python!
Lab 3: First Script
- Create a file called
intro.py - Add print statements
- Run with
python3 intro.py - Modify and re-run
# Lab 3: Create intro.py
# intro.py
print("=" * 40)
print(" Welcome to DevOps Python Course!")
print("=" * 40)
print()
print("Day 1: Introduction to Programming")
print("Today we learned:")
print(" - What programming is")
print(" - How to install Python")
print(" - Using the REPL")
print(" - Writing our first script")
print()
print("Let's continue to Day 2!")
print("=" * 40)
# Run: python3 intro.py
Lab 4: Code Editor Setup
- Install VS Code (if not installed)
- Install Python extension
- Create a Python file and run it
- Use the integrated terminal
📝 Practice Exercises
- Write a program that prints your name and favorite language
- Use the REPL to calculate: 15 * 8 + 22
- Create a script that prints a box with your name inside
- Experiment with
print()usingsepandendparameters
💡 DevOps Relevance
Why this matters:
- Scripts: Automate repetitive tasks
- REPL: Quick testing and debugging
- print(): Logging and debugging output
- Comments: Document automation scripts
✅ Day 1 Checklist
- Python 3 installed and working
- Can use the Python REPL
- Wrote and ran first Python script
- Understand print() function
- Know how to write comments
- Understand Python indentation rules