Day 1: Welcome to Python — Your Journey Begins
🐍 Day 1: Welcome to Python — Your Journey Begins
1. Learning Objectives
By the end of Day 1, you will be able to:
- Understand what Python is and why it's one of the most popular programming languages in the world
- Set up Python on your computer and write your first program
- Use variables to store data
- Identify and work with Python's four basic data types: integers, floats, strings, and booleans
- Use the
type()andprint()functions to inspect your code
2. Concept Explanation
2.1 What is Python?
Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum in 1991. Its design philosophy emphasizes code readability — you can often read Python code like plain English.
Why Python?
| Strength | Real-World Use |
|---|---|
| Readable syntax | Great for beginners and teams |
| Massive ecosystem | Web dev, data science, AI, automation, scripting |
| Cross-platform | Runs on Windows, macOS, Linux |
| Interpreted | No compiling — write and run instantly |
| Dynamically typed | No need to declare variable types upfront |
Who uses Python? Google, Netflix, NASA, Spotify, Instagram — and millions of developers worldwide.
2.2 Installation & Environment Setup
Step 1 — Check if Python is already installed:
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and type:
python --version
# or
python3 --version
If you see something like Python 3.11.x or Python 3.12.x, you're good to go.
Step 2 — If not installed:
- Go to python.org/downloads
- Download the latest Python 3.x (3.11 or 3.12 as of 2024)
- Important: Check the box that says "Add Python to PATH" during installation on Windows
Step 3 — Your first program:
Create a file called hello.py and write:
print("Hello, Python learner!")
Run it from the terminal:
python hello.py
You should see: Hello, Python learner!
🎉 Congratulations — you just wrote and executed Python code!
Interactive Mode (IDLE/REPL): Just type python in your terminal. You'll see >>> — this is an interactive Python shell where you can type code line by line and see results instantly. It's a fantastic sandbox for experimenting.
2.3 Variables
A variable is a named container that stores data in memory. Think of it as a labeled box.
# The variable 'name' stores the text "Alice"
name = "Alice"
# The variable 'age' stores the number 25
age = 25
# You can use variables anywhere you'd use raw values
print(name) # Output: Alice
print(age) # Output: 25
Variable naming rules:
- Must start with a letter or underscore
_ - Can contain letters, numbers, underscores
- Case-sensitive:
score,Score, andSCOREare three different variables - Use snake_case (lowercase with underscores) — the Python convention
user_name = "Bob" # ✅ Good
total_score = 95 # ✅ Good
2nd_place = "Alice" # ❌ Cannot start with a number
my-variable = 10 # ❌ Cannot use hyphens
2.4 Four Basic Data Types
Every value in Python has a type. These are the four fundamental ones:
🔢 int — Integers (whole numbers)
students = 30
temperature = -5
year = 2026
🔣 float — Floating-point numbers (decimals)
price = 19.99
pi = 3.14159
negative = -0.5
📝 str — Strings (text)
Wrapped in single or double quotes:
message = "Hello, World!"
name = 'Maria'
empty = "" # Empty string
number_str = "42" # This is a string, NOT a number!
✅ bool — Booleans (True/False)
is_enrolled = True
has_passed = False
Note:
TrueandFalsemust be capitalized.trueandfalsewill cause errors.
2.5 Inspecting Types with type()
The type() function tells you what type a value is:
print(type(42)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type("Hello")) # <class 'str'>
print(type(True)) # <class 'bool'>
Use this whenever you're unsure what type you're dealing with — it's a priceless debugging habit!
3. Code Examples (Well-Commented)
Here's a complete script tying everything together. Type this into a file called day1_demo.py and run it:
# ============================================
# Day 1: Variables and Basic Data Types
# ============================================
# --- Integers ---
year_founded = 1991
python_age = 2026 - year_founded
print("Python was founded in", year_founded)
print("Python is", python_age, "years old")
print("Type of python_age:", type(python_age))
# --- Floats ---
version = 3.12
rating = 9.8
print("\nCurrent version:", version)
print("Developer rating:", rating, "/ 10")
print("Type of rating:", type(rating))
# --- Strings ---
creator = "Guido van Rossum"
tagline = 'Python: Code with clarity'
print("\nCreated by:", creator)
print(tagline)
print("Type of creator:", type(creator))
# --- Booleans ---
is_fun = True
is_hard = False
print("\nIs Python fun?", is_fun)
print("Is Python hard?", is_hard)
print("Type of is_fun:", type(is_fun))
# --- Dynamic typing ---
# Variables can change type during execution!
x = 100
print("\nx is:", x, "| type:", type(x))
x = "Now I'm a string!"
print("x is:", x, "| type:", type(x))
x = 3.14
print("x is:", x, "| type:", type(x))
Expected output:
Python was founded in 1991
Python is 35 years old
Type of python_age: <class 'int'>
Current version: 3.12
Developer rating: 9.8 / 10
Type of rating: <class 'float'>
Created by: Guido van Rossum
Python: Code with clarity
Type of creator: <class 'str'>
Is Python fun? True
Is Python hard? False
Type of is_fun: <class 'bool'>
x is: 100 | type: <class 'int'>
x is: Now I'm a string! | type: <class 'str'>
x is: 3.14 | type: <class 'float'>
4. Hands-On Exercises
Try these on your own before looking at the solutions. Use the interactive Python shell or a .py file.
Exercise 1: Personal Profile Variables
Create variables for your name, age, height in meters, and student status. Print each one along with its type.
Exercise 2: Type Detective
What is the type of each value below? Predict first, then verify with type():
a = 100
b = "100"
c = 100.0
d = -10
e = "True"
f = True
Exercise 3: Spot the Error
Which of these variable names are invalid and why?
my-var, _private, 1st_place, firstName, user_name, my var, True
Exercise 4: String or Number?
Predict what happens when you run:
x = "5"
y = 10
print(x + y)
Then fix it so it works correctly. (Hint: remember type casting? We'll cover it more tomorrow, but try int() or str())
Exercise 5: Dynamic Typing Explorer
Write a script where one variable holds an int, then a float, then a str, then a bool. Print the variable and its type after each assignment.
5. Applied Challenge Task 🏗️
Health Profile Calculator
Build a simple script that:
- Creates variables storing:
- Your name (string)
- Your age (integer)
- Your height in meters (float, e.g., 1.75)
- Your weight in kilograms (float, e.g., 68.5)
- Whether you exercise regularly (boolean)
- Calculates your BMI using the formula:
BMI = weight / (height ** 2) - Prints a nicely formatted summary like:
=== HEALTH PROFILE ===
Name: Maria
Age: 28 years
Height: 1.65 m
Weight: 62.0 kg
BMI: 22.77
Exercises: True
======================
Stretch goal: Add a comment at the top explaining what the script does, and use type() to verify BMI is a float.
6. Brief Review Summary
| Concept | Key Points |
|---|---|
| Python | High-level, interpreted, readable — great for everything |
| Setup | Install from python.org, use python command to run |
| Variables | Named storage boxes — use snake_case, descriptive names |
| int | Whole numbers: 42, -7, 2026 |
| float | Decimals: 3.14, -0.5, 2.0 |
| str | Text in quotes: "hello", 'world' |
| bool | Truth values: True, False |
| type() | Your best friend for debugging — reveals any value's type |
| Dynamic typing | Variables can hold any type; type can change at runtime |
7. Preview of Next Topic — Day 2
Tomorrow we'll build on today's foundation and learn:
- Operators — arithmetic (
+,-,*,/,//,%,**), comparison (==,!=,>,<), and logical (and,or,not) - Input/Output — using
input()to get data from the user - Type Casting — converting between types with
int(),float(),str(),bool()
🎯 Your Action Items for Day 1:
- ✅ Install Python (if not already) and run
hello.py - ✅ Complete all 5 exercises
- ✅ Complete the Health Profile Calculator challenge
- ✅ Play around in the interactive Python shell — break things, fix them, experiment!
Comments
Post a Comment
Leave us your comments here...