Python & Software Engineering
A Comprehensive Learning Journey
Chapter 1: General Theory & Reference
Python Fundamentals & Syntax Reference
Core concepts, syntax patterns, and essential reference material for Python programming.
Page 1 of 10
1.1 What is Programming?
Programming is the art of giving instructions to a computer. Imagine you're teaching a very literal friend to make a sandwich.
You can't just say "make a sandwich"—you need to break it down:
• Open the bread bag
• Take out two slices
• Open the peanut butter jar
• Get a knife...
Programming is exactly this: breaking down tasks into tiny, precise steps a computer can follow.
Why Do We Need Programming?
Computers are incredibly fast at following instructions but completely unable to think for themselves. They need:
• Explicit instructions - every single step spelled out
• Unambiguous commands - no room for interpretation
• Logical structure - organized, sequential steps
1.2 How Computers Actually Work (Simplified)
Let's build intuition about what happens when code runs.
The Computer's Brain: CPU and Memory
Think of your computer as having:
1. The CPU (Central Processing Unit) - The "brain"
• Performs calculations incredibly fast
• Executes instructions one at a time (or in parallel on modern CPUs)
• Can do basic operations: add, subtract, compare, move data
2. Memory (RAM) - The "short-term memory"
• Stores data temporarily while programs run
• Think of it as a giant spreadsheet with billions of cells
• Each cell has an address (like house numbers on a street)
• When you turn off the computer, RAM is erased
3. Storage (Hard Drive/SSD) - The "long-term memory"
• Keeps files permanently
• Slower than RAM but persists when powered off
From Code to Execution
When you write Python code:
1. You write code in a text file (source code)
2. Python reads and interprets your code
3. Python translates it to instructions the CPU understands
4. CPU executes those instructions
5. Results appear on your screen
Python is an interpreted language, meaning it reads and executes your code line by line, like following a recipe step by step.
1.3 Why Python?
Python was created in 1991 by Guido van Rossum with a philosophy: code should be readable and beautiful.
Python's Advantages for Beginners
1. Readable Syntax
Compare Python to other languages:
Page 2 of 10
# Python - looks like English!
if temperature > 30:
print("It's hot outside")
// Java - more complex syntax
if (temperature > 30) {
System.out.println("It's hot outside");
}
2. Less Boilerplate
You can write powerful programs in just a few lines.
3. Forgiving
Python handles many technical details automatically (like memory management).
4. Versatile
Used for web development, data science, automation, AI, and more.
5. Huge Community
Millions of developers = tons of learning resources and help.
Page 3 of 10
1.4 Your First Python Concepts
Variables: Containers for Data
A variable is a named container that holds a value. Think of it as a labeled box.
# Creating a variable
name = "Alice"
age = 25
temperature = 72.5
is_sunny = True
Key Rules:
• Variable names should be descriptive
• Use lowercase with underscores: user_age not UserAge
• Start with a letter, not a number
• No spaces in names
Data Types: What Kind of Data?
Python has several basic data types:
1. Integers (int) - Whole numbers
score = 100
temperature = -5
year = 2024
2. Floating-Point Numbers (float) - Decimals
price = 19.99
pi = 3.14159
temperature = 98.6
3. Strings (str) - Text
name = "Alice"
message = 'Hello, World!'
book_title = "The Great Gatsby"
Strings can use single ' or double " quotes—they're the same!
String Special Features:
# Strings can span multiple lines
long_text = """This is a
multi-line
string"""
# Concatenation (joining)
first_name = "Alice"
last_name = "Smith"
full_name = first_name + " " + last_name # "Alice Smith"
# Repetition
laugh = "ha" * 3 # "hahaha"
4. Booleans (bool) - True or False
is_raining = True
has_license = False
Only two possible values: True or False (capital T and F matter!)
Page 4 of 10
The None Type
None is a special value meaning "nothing" or "no value":
result = None # Represents absence of a value
Page 5 of 10
1.5 Basic Operations
Arithmetic Operations
# Addition
total = 10 + 5 # 15
# Subtraction
difference = 10 - 5 # 5
# Multiplication
product = 10 * 5 # 50
# Division (always returns a float)
quotient = 10 / 5 # 2.0
# Integer Division (rounds down)
result = 10 // 3 # 3
# Modulo (remainder)
remainder = 10 % 3 # 1
# Exponentiation (power)
squared = 10 ** 2 # 100
Operator Precedence
Like math, Python follows order of operations (PEMDAS):
result = 2 + 3 * 4 # 14 (not 20!)
# Multiplication happens first: 3 * 4 = 12, then 2 + 12 = 14
# Use parentheses to control order
result = (2 + 3) * 4 # 20
Comparison Operations
Compare values and get True or False:
5 == 5 # True (equal to)
5 != 3 # True (not equal to)
5 > 3 # True (greater than)
5 < 3 # False (less than)
5 >= 5 # True (greater than or equal)
5 <= 3 # False (less than or equal)
Important: Use == to compare, not = (which assigns!)
1.6 Input and Output
Printing to the Screen
# Basic print
print("Hello, World!")
# Print multiple things
print("My name is", "Alice") # My name is Alice
# Print variables
age = 25
print("I am", age, "years old") # I am 25 years old
Page 6 of 10
Getting User Input
# Ask user for input (returns a string)
name = input("What is your name? ")
print("Hello,", name)
# Converting input to numbers
age_text = input("How old are you? ")
age = int(age_text) # Convert string to integer
Page 7 of 10
1.7 Comments: Notes to Yourself
Comments are notes in your code that Python ignores. They're for humans!
# This is a single-line comment
age = 25 # You can also put comments after code
"""
This is a multi-line comment
(technically a string that's not assigned)
Used for longer explanations
"""
When to use comments:
• Explain WHY you did something (not what—code shows what)
• Mark sections of code
• Add reminders or TODOs
1.8 Type Conversion
Sometimes you need to convert between types:
# String to Integer
age_str = "25"
age_int = int(age_str) # 25
# Integer to String
score = 100
score_str = str(score) # "100"
# String to Float
price_str = "19.99"
price = float(price_str) # 19.99
# Check type of a variable
type(25) # <class 'int'>
type("hello") # <class 'str'>
type(3.14) # <class 'float'>
1.9 Practice Exercises
Try these on your own (we'll set up Python in Chapter 4, but think through them now):
Exercise 1: Temperature Converter
Think through: How would you convert Fahrenheit to Celsius?
Formula: C = (F - 32) × 5/9
Exercise 2: Personal Greeting
Get user's name and age, print: "Hello [name], you were born in approximately [year]"
Exercise 3: Simple Calculator
Get two numbers from user, print their sum, difference, product, and quotient.
1.10 Key Takeaways
■ Programming = giving precise instructions to computers
■ Variables = named containers for data
Page 8 of 10
■ Data types: int, float, str, bool, None
■ Operations: arithmetic, comparison
■ print() = output to screen
■ input() = get user input
■ Comments = notes for humans (use #)
Page 9 of 10
1.11 Quick Reference: Chapter 1
# VARIABLES
name = "Alice"
age = 25
# DATA TYPES
integer = 42 # int
decimal = 3.14 # float
text = "Hello" # str
yes_no = True # bool
nothing = None # None
# OPERATIONS
10 + 5 # 15 (addition)
10 - 5 # 5 (subtraction)
10 * 5 # 50 (multiplication)
10 / 5 # 2.0 (division)
10 // 3 # 3 (integer division)
10 % 3 # 1 (modulo/remainder)
10 ** 2 # 100 (exponent)
# COMPARISONS
5 == 5 # True
5 != 3 # True
5 > 3 # True
5 < 3 # False
# INPUT/OUTPUT
print("Text") # Output
name = input("Your name? ") # Input (returns string)
# TYPE CONVERSION
int("25") # string → integer
float("3.14") # string → float
str(100) # any type → string
■ End of Chapter 1
You've learned:
• What programming is and how computers work
• Why Python is a great first language
• Variables and data types
• Basic operations
• Input/output basics
Up next: Chapter 2 will contextualize everything by exploring what web applications are and how our reading app will work.
This will help you see where all this Python knowledge is leading!
Ready for Chapter 2? Take your time to digest these concepts—understanding the foundations deeply is more important than
speed.
Page 10 of 10