14 min read Hands-on Practical Lesson 2 of 16
Course 03 · Part 1 — Thinking & Basics

Your First Python Program

From Writing Code to Machine Execution: Your First Practical Milestone

In the previous lesson, we explored what programming is and why Python is such a clean, powerful language to begin with. Now, we leave pure theory behind and give the computer a genuine instruction. We will write our first Python script file, run it inside the terminal, and trace what happens inside the CPU, memory, and operating system when our human-readable characters turn into pixels on the screen.

The First Step in Software Creation

Every monumental software system—be it a spacecraft flight controller, a messaging platform serving billions of users, or a modern artificial intelligence model—started with a single, humble instruction. Today, you take your first hands-on step by executing code you write yourself.

01 What Truly is a Python Program?

A Python Program is a structured sequence of one or more instructions (statements) written according to the rules of the Python language. For instance:

print("Hello, World!")

This is a complete, self-contained Python program. Here, we give the computer a clear command: “Display the text 'Hello, World!' as output on the screen.”

As programs grow in complexity, the number of instructions increases. A simple command-line calculator might contain 50 statements, while a modern web browser contains tens of millions. Yet every complex program rests on this exact same foundation: precise, orderly instructions executed one by one.

02 Where Do We Write Code? Editor vs. Runtime

To compose instructions, we use a Code Editor or an IDE (Integrated Development Environment). Popular options include:

Visual Studio Code
Most popular, lightweight, & extensible
PyCharm
Powerful dedicated Python IDE
Sublime Text / Cursor
Fast, modern AI-augmented editors

Keep this fundamental distinction clear:

Code Editor: This is simply your notebook or canvas. An editor cannot run or execute code on its own—it merely edits plain text files.
Python Runtime: This is the actual engine installed on your OS that parses your text, translates it into bytecode, and coordinates with hardware to perform work.

03 What Comes with Python?

When you install Python (from python.org), you primarily receive two core components: the CPython Interpreter and the Standard Library (a rich collection of pre-built tools for file handling, math, networking, and more).

To verify that Python is correctly installed and accessible in your system's PATH, open your terminal (Command Prompt, PowerShell, or macOS/Linux Terminal) and enter:

python --version

(On some systems, particularly Linux or macOS, you may need to type python3 --version). If you see an output such as Python 3.12.x, your computer is ready to run Python programs!

04 Python Interactive Mode (REPL)

If you type simply python (or python3) in your terminal without any filename and press Enter, Python starts in Interactive Mode. In computer science, this environment is called a REPL (Read-Eval-Print Loop).

Terminal — Python REPL
Python 3.12.0 (main, Oct 2026) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello")
Hello
>>> 5 + 7
12
>>> exit()

In the REPL, every instruction you submit is read immediately, evaluated, and printed right back to your screen. This provides an excellent scratchpad for quick mathematical computations or sanity-checking a single function before writing larger software.

05 Writing a Real Script Program

Interactive mode is ephemeral—the moment you close the terminal window, everything you typed vanishes into thin air. Real-world applications need to be saved permanently in files. Let us create a script:

1
Create the file: In your project folder, create a file named hello.py. The .py extension signifies that this is a Python source code file.
2
Type the instruction:
print("Hello, Byteion!")
3
Execute from your terminal:
python hello.py
4
Observe the output:
Hello, Byteion!

🎉 Congratulations! You have successfully written and executed your very first Python program!

06 What Truly Happened Under the Hood?

Connecting this back to our deep systems knowledge from Course 02 (How Software Actually Works), let us trace every step that occurred when you pressed Enter:

1. Terminal Invocation The OS shell asks the kernel to spawn a new process for python, passing hello.py as a command-line argument.
2. File System Read The OS reads the bytes of hello.py from storage (SSD) into the Python process's virtual memory space.
3. CPython Compiler CPython's lexer and parser construct an Abstract Syntax Tree (AST), which is compiled into intermediate Bytecode (LOAD_NAME, CALL_FUNCTION).
4. Python VM (PVM) The Virtual Machine loop evaluates the bytecode and invokes the operating system's standard output (stdout) via the write() system call.
5. Terminal Display The terminal emulator rasterizes glyphs into the screen framebuffer, lighting up pixels to display: Hello, Byteion!

07 Source Code: Bridging Human Thought & Machine State

What you typed into that file is called Source Code. It is crafted primarily for human comprehension. In well-written source code, the programmer's intent is immediately evident:

price = 1000
discount = 20

Any human reader intuitively grasps that an item has a price of 1,000 and a discount of 20. The underlying CPU, however, has zero understanding of "price" or "discounts"—it only operates on binary voltage states, registers, and memory offsets. Source code is the universal translator that bridges human reason with silicon execution.

08 What is `print()` and How Does It Work?

The star of our first instruction is print().

In Python, a Function is a pre-packaged procedure or tool designed to perform a specific task when called. print() is a Built-in Function provided directly by Python. Its sole mission is to take whatever you place between its parentheses () and transmit it as text to standard output.

print_examples.py
print("Hello") # Display text
print(100) # Display numbers
print(10 + 20) # Display evaluated arithmetic results
Output:
Hello
100
30

09 Why Must Text Be Wrapped in Quotation Marks?

Notice that writing print(100) required no quotation marks, while print("Hello") required quotes on both sides. Why is this necessary?

Without quotation marks, Python assumes Hello is an instruction, a keyword, or a variable stored in memory! By wrapping characters in quotes, you inform Python: “Do not interpret this as a command—treat this as literal text data.” In computer science, this literal text sequence is known as a String.

Double Quotes:
print("Hello World")
Single Quotes:
print('Hello World')

In Python, both single and double quotes are equally valid—just make sure your opening and closing quotes match.

10 Python Computes Arithmetic Directly

Python operates as a high-precision calculator, evaluating arithmetic expressions directly:

print(10 + 20) # Addition: 30
print(50 - 15) # Subtraction: 35
print(6 * 7) # Multiplication: 42
print(100 / 4) # Division: 25.0
Key observation: When you write print("10 + 20"), the output is the literal string 10 + 20. But when written without quotes as print(10 + 20), Python calculates the sum and outputs the numerical value 30!

11 & 12 Sequential Execution & Multiple Statements

A program naturally consists of multiple lines. By default, Python processes instructions sequentially from top to bottom, one statement after another:

print("Line 1")
print("Line 2")
print("Line 3")

The output on your screen appears in the exact same order. In upcoming lessons, we will explore control flow constructs (such as if/else conditionals and loops) that allow us to branch or repeat this linear path.

13 What are Comments and Why Use Them?

Notes or annotations written within code for human developers to read are called Comments. In Python, any line or portion of a line beginning with a hash character (#) is a comment.

# This is a comment — the Python runtime ignores it entirely
print("Hello")
# Calculate total order amount with shipping
print(1000 + 200)

Comments have zero impact on program execution speed or binary state. They exist purely to communicate intent to human teammates and your future self.

14 What Happens When Code Has an Error?

Suppose you make a typo and omit the closing parenthesis:

print("Hello"

The moment you run the file, Python halts execution and outputs a SyntaxError:

SyntaxError: '(' was never closed

Do not fear errors!

Encountering an error is never a sign of failure in software engineering. In fact, an error message is the most constructive feedback a computer can provide! Python pinpoints exactly which line failed and what went wrong so that you can correct the issue immediately.

15 & 16 Script Mode vs. Interactive Mode

Interactive Mode (REPL)
  • • Execute one line at a time directly in terminal.
  • • Immediate feedback loop.
  • • Code vanishes when terminal closes.
  • • Ideal for quick testing and debugging snippets.
Script Mode (.py Files)
  • • Code is saved permanently on disk.
  • • Build complex, multi-file software projects.
  • • Re-run effortlessly at any time.
  • • The standard for real-world software development.

17 Our First Foundational Mental Model

Keep this clear flow in mind throughout your programming journey:

Real-World Problem → Python Code → Python Runtime → Computer Hardware → Output

18 Hands-On Practice Challenges

The best way to build engineering intuition is to write code yourself. Open a practice.py file in your editor and complete these four challenges:

Challenge 1: Print Your Name Print your full name as output to the terminal.
print("Your Name")
Challenge 2: Your Favorite Motto or Quote Print a motivational quote about software engineering.
print("I love solving problems with code!")
Challenge 3: Direct Arithmetic Calculation Calculate and display the sum of 25 and 75 directly without quotation marks.
print(25 + 75)
Challenge 4: Multi-Line Welcome Banner Use sequential print() statements to create a formatted welcome banner.
print("================================")
print("Welcome to Byteion Academy!")
print("Year: 2026")
print("================================")

19 🧠 Key Takeaways & Summary

File Extension: Python source files always use the .py extension.
print() Function: The primary tool to display text, numbers, or calculated values on the screen.
Strings: Literal text data must be enclosed in quotation marks (" " or ' ') to distinguish it from variables or keywords.
Comments: Lines prefixed with # are ignored by the Python interpreter and serve as notes for humans.
Errors: Errors are natural and instructive; reading traceback messages is how developers pinpoint and fix bugs.

Next Lesson: Variables & Data

Outputting fixed values with print() is only the beginning. To store user names, ages, and balances in memory under identifiable labels, we need Python's core building blocks—Variables and Data Types!