Courses/Python/Introduction to Python

    Lesson 1 • Beginner

    Python Fundamentals – Getting Started

    Beginner-Safe, No Assumptions — Learn Python from absolute zero. Every concept is explained before it's used.

    What You'll Learn in This Lesson

    • What Python is and why it's the best first language
    • How to check if Python is installed on your computer
    • How to write and run your very first Python program
    • What print() does and how strings, numbers, and comments work
    • How to take input from the user with input()
    • What errors mean — and why they're totally normal

    🔧 Before You Start: Do You Have Python?

    Many computers already have Python installed. Let's check if yours does.

    Windows:

    Open Command Prompt (search "cmd" in Start menu) and type:

    python --version

    macOS / Linux:

    Open Terminal and type:

    python3 --version

    If you see something like "Python 3.x.x" — you're ready!

    📁 Running Python on Your Computer

    Let's create and run your very first Python program. Follow these steps exactly:

    Step 1: Create a file

    Open any text editor (Notepad on Windows, TextEdit on Mac, or any code editor). Create a new file and name it exactly:

    hello.py

    The .py tells your computer "this is a Python file".

    Step 2: Write this code

    Type (or copy) this single line into your file:

    print("Hello, World!")

    Step 3: Save the file

    Save it somewhere you can find it easily (like your Desktop or Documents folder).

    Step 4: Open your terminal

    • Windows: Search "cmd" in Start menu → open Command Prompt
    • macOS: Open Finder → Applications → Utilities → Terminal
    • Linux: Press Ctrl+Alt+T or search "Terminal"

    Step 5: Navigate to your file

    Use the cd command to go to where you saved your file:

    cd Desktop

    (Replace "Desktop" with wherever you saved the file)

    Step 6: Run the program

    Windows:

    python hello.py

    macOS / Linux:

    python3 hello.py

    ✅ Expected Output:

    Hello, World!

    If you see this, congratulations! You just ran your first Python program.

    1️⃣ What Is Python? (Plain English)

    Python is a programming language.

    A programming language is a way for humans to give instructions to a computer. Think of it like learning a new language — but instead of talking to people, you're talking to machines.

    Computers do nothing by themselves. They only follow instructions exactly as written. Your job is to write those instructions clearly.

    Python is designed so that:

    • Code is easy to read
    • Words look close to English
    • Beginners don't get overwhelmed by symbols

    Python is used for:

    • Websites and web apps
    • Automation (making repetitive tasks automatic)
    • Artificial Intelligence (AI)
    • Data analysis
    • Games
    • Finance and science

    But before building anything, we must learn the core basics. Let's start.

    🌍 Why Python? Real-World Proof

    Python isn't just popular in classrooms — it powers some of the biggest products on the planet:

    Instagram

    Built their entire backend with Python (Django framework). 2 billion users.

    YouTube

    Python runs recommendation algorithms and internal tooling.

    Spotify

    Uses Python for data pipelines and music analysis.

    NASA

    Scientists write Python scripts to analyse space mission data.

    Netflix

    Python powers their data science and content personalisation.

    Reddit

    The original site was written entirely in Python.

    Why is Python so popular for all of these?

    It's designed to be human-readable. Look at this comparison — both programs do the exact same thing:

    Java (another language):

    System.out.println("Hello");

    Python:

    print("Hello")

    Python's creator, Guido van Rossum, designed it to look like pseudocode.

    That means you can often guess what Python code does before you've been taught it — which makes learning dramatically faster.

    By Lesson 5 of this course, you'll be writing Python scripts that automate real tasks on your own computer.

    2️⃣ What Is a Program?

    A program is simply a list of instructions that a computer follows.

    Example in human language:

    1. Show a message on the screen
    2. Add two numbers together
    3. Display the result

    In Python, this looks different — but the idea is the same:

    • Instructions are written line by line
    • Python reads and runs them from top to bottom
    • Each line does one thing

    🧠 How Python Executes Code: The Mental Model

    Before you write your first real instruction, it helps to picture what actually happens when you run Python code:

    1. 1
      You write code in a .py file using any text editor
    2. 2
      You run it by typing python hello.py in your terminal
    3. 3
      Python reads line 1, executes it immediately, then moves to line 2, executes it, and so on until the end
    4. 4
      Output appears in the terminal as each line runs

    Python reads your code the same way you read a book — left to right, top to bottom.

    It never skips ahead and never goes backwards (unless you tell it to). This is called sequential execution.

    Watch the guaranteed order:

    Your code:

    print("First")
    print("Second")
    print("Third")

    Output (always in this order):

    First
    Second
    Third

    Line 1 always runs before line 2. Line 2 always runs before line 3. There are no surprises.

    3️⃣ Your First Python Instruction: print()

    What does print() do?

    print() tells Python: "Show this on the screen."

    It's the most basic way to make Python display something to you.

    Example:

    print("Hello, world")

    Let's break this down piece by piece:

    • print → a function (a built-in action Python already knows how to do)
    • () → parentheses mean "run this action now"
    • "Hello, world" → the text you want to display

    4️⃣ Quotes (" " and ' ') — VERY IMPORTANT

    This is one of the most important things to understand early:

    Python must know what is text and what is code.

    Text MUST be wrapped in quotes. Without quotes, Python gets confused.

    This works:

    print("Hello")
    print('Hello')

    This does NOT work:

    print(Hello)

    Why does this fail?

    Without quotes, Python thinks:

    • Hello is a variable name (we'll learn about these soon)
    • But no variable called Hello exists yet
    • So Python throws a NameError — it can't find what you're referring to

    🧠 Rule (memorise this):

    If you want to show words or sentences, they MUST be inside quotes.

    Double vs Single Quotes:

    Both are valid: "Hello" and 'Hello'

    Pick one style and use it consistently. Most beginners use double quotes " ".

    5️⃣ Strings (What Text Is Called in Programming)

    In Python, text has a special name: string.

    A string is any sequence of characters wrapped in quotes.

    Examples of strings:

    "Hello"
    "123"
    "This is a sentence"
    "I love Python!"

    ✂️ String Operations: Doing Things with Text

    A string isn't just something you print — you can do things with it. Here are the four most useful operations for beginners:

    1. Length — how many characters?

    print(len("Hello"))    # Output: 5
    print(len("Hi there")) # Output: 8 (spaces count!)

    len() counts every character — including spaces, numbers, and punctuation.

    2. Repetition — repeat a string

    print("ha" * 3)    # Output: hahaha
    print("-" * 20)    # Output: -------------------- (useful for dividers!)

    The * operator repeats a string a set number of times.

    3. Concatenation — join two strings together

    first = "Learn"
    second = "Python"
    print(first + " " + second)  # Output: Learn Python

    4. Indexing — get one character by position

    word = "Python"
    print(word[0])   # Output: P
    print(word[1])   # Output: y

    Python starts counting from zero, not one. So word[0] is the first character. This will make more sense as you progress — just plant that seed now.

    🧪 Try It Yourself — String Operations

    Run this code and observe each output. Then try changing 'word' to your own name and run again.

    Try it Yourself »
    Python
    word = "Python"
    
    # Length
    print(len(word))           # How many characters?
    
    # Repetition
    print("=" * 20)            # Divider line
    print("Go " * 3)           # Repeat "Go "
    
    # Concatenation
    print("I love " + word)   # Join strings
    
    # Indexing
    print(word[0])             # First character
    print(word[1])             # Second character

    6️⃣ Comments (#) — Leaving Notes in Your Code

    Sometimes you want to write notes in your code that Python should ignore completely.

    Anything after the # symbol is a comment — Python skips it.

    # This is a comment - Python ignores this line
    print("Hello")  # This part is also ignored

    Why do comments exist?

    • To explain what your code does
    • To leave reminders for yourself
    • To help others understand your code
    • To temporarily disable code without deleting it

    ❌ Bad comment (states the obvious):

    print("Hello")  # prints hello

    ✅ Good comment (explains why):

    # Greet user when app starts
    print("Hello")

    🧪 Try It Yourself — Printing Text

    Run your first Python program and see the output. Notice how each print() shows on a new line.

    Try it Yourself »
    Python
    # My first Python program
    print("Welcome to Python")
    print("This is my first program")
    print("I am learning step by step")

    7️⃣ Numbers (Not Text)

    Numbers are written without quotes.

    Examples:

    print(10)
    print(3.14)
    print(100 + 50)

    This is a number:

    10

    Python can do math with it

    This is text (a string):

    "10"

    Python treats it as letters

    They look similar — but Python treats them completely differently. This matters when you start doing calculations.

    8️⃣ Variables (Storing Information)

    A variable is like a labeled box that stores a value.

    You give the box a name, and put something inside it.

    Example:

    age = 16

    Read this as: "Create a box called age and put the number 16 inside it."

    Now you can use that value later:

    age = 16
    print(age)

    This will display: 16

    Variables can store different types of values:

    name = "Alex"        # text (string)
    age = 16             # whole number (integer)
    height = 1.75        # decimal number (float)
    is_student = True    # true/false value (boolean)

    🔁 How Variables Actually Work

    Two things about variables that confuse almost every beginner — let's clear them up now.

    1. Variables can be re-assigned (updated)

    A variable isn't locked to its first value. You can change it as many times as you like:

    age = 16
    print(age)   # Output: 16
    
    age = 17     # Changed our minds — it's 17 now
    print(age)   # Output: 17

    The old value (16) is simply overwritten. Python only remembers the most recent value.

    2. = does NOT mean "equals"

    In Python, = means "store this value". It does not mean "these two things are equal".

    age = 16    # Store the value 16 in a box called age

    For equality checks, Python uses == (double equals). You'll learn about this in the next lesson. For now, just remember: one = stores, two == compares.

    3. Naming rules — what's allowed?

    ✅ Allowed:

    • name
    • first_name
    • age2
    • total_score

    ❌ Not allowed:

    • 2age — can't start with a number
    • first name — no spaces
    • my-var — hyphens not allowed

    9️⃣ Data Types: str, int, float, bool

    Python organizes data into different types. Here are the four most common:

    str (String) — Text

    name = "Alex"
    message = "Hello there!"

    Any text wrapped in quotes

    int (Integer) — Whole Numbers

    age = 16
    score = 100

    Numbers without decimal points

    float (Floating Point) — Decimal Numbers

    price = 4.99
    height = 1.75

    Numbers with decimal points

    bool (Boolean) — True or False

    is_student = True
    has_license = False

    Only two possible values: True or False (note the capital letters)

    ⚡ Why Data Types Actually Matter

    Data types aren't just labels — they change how Python behaves with your data. The same symbol can do completely different things depending on the type:

    Strings with +:

    "5" + "3"   # Result: "53"

    String + string = concatenation (joined together)

    Numbers with +:

    5 + 3       # Result: 8

    Number + number = addition (actual math)

    This is why types matter. Python does different things with the same symbol based on the type of data you give it. Understanding this saves you from hours of debugging confusion.

    The type() function — ask Python "what type is this?"

    If you're ever unsure what type a value or variable is, just ask Python directly:

    print(type(42))        # <class 'int'>
    print(type(3.14))      # <class 'float'>
    print(type("hello"))   # <class 'str'>
    print(type(True))      # <class 'bool'>

    type() is one of Python's most useful debugging tools. When something isn't working as expected, checking the type often reveals the problem immediately.

    🧪 Try It Yourself — Types in Action

    Run this and observe how the same operators behave differently depending on type. Can you predict the output before running?

    Try it Yourself »
    Python
    # Types change behavior!
    print("5" + "3")    # String + String = ?
    print(5 + 3)        # Number + Number = ?
    
    # Check the type of anything
    print(type(42))
    print(type(3.14))
    print(type("hello"))
    print(type(True))
    
    # What happens with string * number?
    print("Go! " * 3)

    🧪 Try It Yourself — Variables

    Create variables and print their values. Try changing the values and running again!

    Try it Yourself »
    Python
    # Create some variables
    name = "Alex"
    age = 16
    height = 1.75
    is_learning = True
    
    # Print them out
    print(name)
    print(age)
    print(height)
    print(is_learning)

    🔟 Printing Multiple Values

    You can print more than one thing at a time by separating values with commas:

    name = "Alex"
    age = 16
    
    print(name, age)

    Output: Alex 16

    Python automatically adds a space between them.

    1️⃣1️⃣ Converting Types with str() — VERY IMPORTANT

    The Problem

    This code causes an error:

    age = 16
    print("Age is " + age)

    Why does this fail?

    • "Age is " → this is text (string)
    • age → this is a number (integer)
    • Python cannot join text and numbers together with +

    The Solution: str()

    str() converts any value into text.

    age = 16
    print("Age is " + str(age))

    Output: Age is 16

    🧠 Rule:

    When joining text and numbers with +, convert the number to text first using str().

    1️⃣2️⃣ f-Strings (The Modern, Easier Way)

    Now that you understand strings and variables, let's learn a cleaner way to combine them.

    What does "f" mean?

    f stands for formatted. An f-string lets you insert variables directly into text.

    Without f-string (the old way we just learned):

    age = 16
    print("I am " + str(age) + " years old")

    Works, but messy and easy to make mistakes.

    With f-string (the modern way):

    age = 16
    print(f"I am {age} years old")

    Much cleaner! And no need for str().

    How it works:

    • Put f before the opening quote
    • Put any variable inside curly braces {}
    • Python automatically replaces {age} with the actual value

    Important Rules for f-Strings:

    • ✅ Must start with f before the quote
    • ✅ Variables go inside curly braces {}
    • ❌ Forgetting the f means no replacement happens

    You can even do math inside f-strings:

    print(f"Total: {10 + 5}")

    Output: Total: 15

    🧪 Try It Yourself — f-Strings

    Practice using f-strings to format output. Try adding your own variables!

    Try it Yourself »
    Python
    # Using f-strings to format output
    price = 4.99
    quantity = 3
    total = price * quantity
    
    print(f"Price per item: {price}")
    print(f"Quantity: {quantity}")
    print(f"Total cost: {total}")

    1️⃣3️⃣ Arithmetic (Math Operations)

    Python can perform calculations just like a calculator:

    a = 10
    b = 3
    
    print(a + b)   # Addition: 13
    print(a - b)   # Subtraction: 7
    print(a * b)   # Multiplication: 30
    print(a / b)   # Division: 3.333...

    Special operators:

    print(a // b)  # Floor division (whole number only): 3
    print(a % b)   # Modulus (remainder): 1
    print(a ** b)  # Exponent (power): 1000

    📐 Arithmetic Deep Dive: Things That Catch Beginners

    Order of operations (PEMDAS / BODMAS)

    Python follows standard maths rules. Multiplication and division happen before addition and subtraction:

    print(2 + 3 * 4)      # Output: 14  (not 20!)
    print((2 + 3) * 4)    # Output: 20  (parentheses change the order)

    Use parentheses whenever you want to control the order. When in doubt, add parentheses — they make your intent clear.

    Division always returns a float in Python 3

    print(10 / 2)    # Output: 5.0  (not 5!)
    print(10 / 3)    # Output: 3.3333...
    print(10 // 3)   # Output: 3    (floor division — whole number only)

    The / operator always returns a decimal (float), even if the result is a whole number. Use // when you need an integer result.

    Modulo (%) — one of the most useful operators

    % gives you the remainder after division. This sounds abstract until you see the pattern:

    # Check if a number is even or odd
    number = 7
    print(number % 2)    # Output: 1 (odd — remainder is 1)
    
    number = 8
    print(number % 2)    # Output: 0 (even — no remainder)

    If number % 2 == 0, the number is even. If it's 1, it's odd. You'll use this pattern constantly in future lessons.

    🧪 Try It Yourself — Arithmetic

    Practice math operations. Try changing the values of a and b!

    Try it Yourself »
    Python
    # Try some math!
    a = 10
    b = 3
    
    print(f"{a} + {b} = {a + b}")
    print(f"{a} - {b} = {a - b}")
    print(f"{a} * {b} = {a * b}")
    print(f"{a} / {b} = {a / b}")
    print(f"{a} to the power of {b} = {a ** b}")

    1️⃣4️⃣ Getting Input From Users

    You can ask the user to type something:

    name = input("Enter your name: ")
    print(f"Hello, {name}!")

    If you need a number from the user:

    age = int(input("Enter your age: "))
    print(f"Next year you will be {age + 1}")

    int() converts the text input into a whole number.

    Mini-Project: Personal Introduction Generator

    You now know enough Python to write a real, useful program. This mini-project combines every concept from this lesson into one coherent script. This is the kind of thing you could show someone to prove you've learned programming.

    Concepts used in this project:

    • Variables (str, int)
    • input() to collect data
    • int() type conversion
    • Arithmetic (subtraction)
    • f-strings for output
    • print() for display

    Stage 1 — Collect information from the user:

    name   = input("What is your name? ")
    age    = int(input("How old are you? "))
    city   = input("What city are you from? ")
    hobby  = input("What is your favourite hobby? ")

    Notice int(input(...)) — we convert immediately because we need to do maths with age.

    Stage 2 — Calculate something interesting:

    years_to_100 = 100 - age
    birth_year   = 2026 - age

    Stage 3 — Display everything with f-strings:

    print("=" * 30)
    print("       About Me")
    print("=" * 30)
    print(f"Hi! My name is {name}.")
    print(f"I am {age} years old, born in {birth_year}.")
    print(f"I live in {city}.")
    print(f"I enjoy {hobby}.")
    print(f"I will turn 100 in {years_to_100} years!")
    print("=" * 30)

    Challenge — extend it yourself:

    Can you add a favourite_food variable and include it in the output? What about adding a school or job variable? The pattern is the same — just add more input() lines and use them in f-strings.

    🧪 Try It Yourself — Personal Introduction Generator

    Change name, age, city, and hobby at the top to your own details, then run it. Can you add a favourite_food variable and include it in the output?

    Try it Yourself »
    Python
    # Personal Introduction Generator
    # (In a real terminal you'd use input() — here we set values directly)
    name   = "Alex"
    age    = 17
    city   = "London"
    hobby  = "coding"
    
    years_to_100 = 100 - age
    birth_year   = 2026 - age
    
    print("=" * 30)
    print("       About Me")
    print("=" * 30)
    print(f"Hi! My name is {name}.")
    print(f"I am {age} years old, born in {birth_year}.")
    print(f"I live in {city}.")
    print(f"I enjoy {hobby}.")
    print(f"I will turn 100 in {years_to_100} years!")
    print("=" * 30)

    1️⃣5️⃣ Common Errors (Normal & Expected)

    Errors happen to everyone — even professional programmers. Here's what the most common ones mean:

    NameError

    print(hello)

    Why: You forgot the quotes around text. Python thinks hello is a variable that doesn't exist.

    Fix: Add quotes: print("hello")

    TypeError

    print("Age: " + 16)

    Why: You tried to join text and a number with +.

    Fix: Use str(16) or an f-string.

    SyntaxError

    print("Hello"

    Why: Something is missing or mistyped — here, the closing parenthesis.

    Fix: Check for missing quotes, parentheses, or colons.

    Remember: Errors are feedback, not failure. They tell you exactly what to fix.

    1️⃣6️⃣ Cheat Sheet (Lesson 1)

    print("text")         → show text on screen
    "Hello"              → string (text)
    10                   → integer (whole number)
    3.14                 → float (decimal number)
    True / False         → boolean (true/false)
    age = 16             → create a variable
    str(16)              → convert number → text
    int("42")            → convert text → number
    f"Age: {age}"        → f-string (insert variables)
    # comment            → note (Python ignores this)
    input("Question: ")  → ask user for input

    1️⃣7️⃣ What You Should Understand Now

    Before moving on, make sure you understand:

    • ✅ How to check if Python is installed on your computer
    • ✅ How to create and run a Python file
    • ✅ What print() does
    • ✅ Why text needs quotes
    • ✅ What strings, integers, floats, and booleans are
    • ✅ How to use comments with #
    • ✅ What variables are and how to create them
    • ✅ Why str() is needed sometimes
    • ✅ How f-strings make formatting easier
    • ✅ Why errors happen and what common ones mean

    Don't worry if some things aren't 100% clear yet. We'll practice more in the next lesson!

    🎉

    Great work — you've finished Lesson 1!

    You now know what Python is, how to run a program, what print() does, and how strings, numbers, and comments work. You've already written your very first Python program — that's huge!

    🚀 Up next: Variables & Data Types — learn how Python stores and remembers information so your programs can actually do things.

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy PolicyTerms of Service