What you'll learn
Programming becomes much easier when you can explain what each line changes. This lesson deliberately focuses on a small set of ideas and revisits them in increasingly realistic examples.
- Explain what a variable stores and how assignment changes its value.
- Distinguish str, int, float and bool and use explicit type conversion safely.
- Predict the order in which assignment, arithmetic and print statements execute.
- Build a Boolean comparison before introducing if / else logic.
- Read a traceback, inspect variables and correct a small script independently.
- Format strings with f-strings, placing values into a readable report.
Your first Python program
Python reads your script from top to bottom. A statement performs an action: assign a value, calculate a result, or print output. You don't need an IDE or a complex app to begin—just a question and a few instructions.
Names and values
device = "SW-01" assigns the string SW-01 to a variable named device. The name points to a value; it is not the value itself.
Print shows a result
print(device) writes the variable's current value to standard output. Writing print("device") prints the literal word device instead.
device = "SW-01"
print(device)
print("device")What are the two printed lines? Reveal explanation after you predict.
First line: SW-01 (the variable value). Second line: device (the literal string).
Run your first .py file outside JoeLearns
You can use the browser editor for every exercise in this path. But if you'd like to practice as a developer or IT technician would, you can install Python and run the same program on your computer right now. No account, editor subscription, or extra packages are necessary.
- Install only if needed. Download Python from the official Python downloads page. For Linux, prefer your distribution's Python package. If Python is already installed, skip straight to the next step.
- Confirm the interpreter runs. Open a fresh terminal (PowerShell on Windows or Terminal on macOS/Linux) and enter:
You should see a Python 3 version. The exact version number can differ from the browser's Python runtime.py --version - Create a script. Make a new folder named
python-practice. Choose a code-friendly plain-text editor: on Windows, Notepad++ is lightweight and highlights Python syntax; on Linux, Vim is available in many terminals but has a learning curve. VS Code is an approachable option on both, and Python IDLE works too. Windows Notepad can save a .py file, but for learning to program it offers fewer coding aids such as Python-aware syntax highlighting, indentation support and error cues. You may be thinking of Notepad++, rather than WordPad. Openfirst_script.pyinside the folder and save these three lines:Check that the filename ends withdevice = "SW-01" print(device) print("device").py, not.py.txt. Code-focused editors make indentation, quotes and accidental .txt extensions easier to notice, but none is required. - Run the file. In File Explorer, open the python-practice folder. Right-click an empty area inside the folder (not the .py file), then choose Open in Terminal if available. Alternatively, click File Explorer’s address bar, type powershell, and press Enter. Both open a terminal in that folder. The built-in terminal in a code editor is fine too. Enter:
The output should be two lines:py first_script.pySW-01anddevice. If Python reports it cannot find the script, check the terminal's current folder and the filename. - Get real feedback from an error. Change
print(device)toprint(devce), save, and run the file again. Read theNameErrortraceback, then correct the typo and rerun it. You've just completed the same debug-and-verify cycle used throughout this path.
Python command not found, script won't run, or unsure what to install?
If py isn't recognized, try python --version and python first_script.py. If neither works, follow the official Windows installation and command troubleshooting guide. For installation and command troubleshooting, see the Official Python Windows guide. If you are on a managed school or work device, ask an administrator before installing software.
Types change how expressions behave
Python keeps text and numeric values distinct. A value that looks like a number can still be a string if it comes from a text source. Learn to check and convert types instead of guessing what an expression will do.
Common built-in types
str stores text, int stores whole numbers, float stores decimal numbers, and bool stores True or False. Python variable names don't require type declarations.
Conversion is deliberate
int("443") produces integer 443. int("not-a-number") raises ValueError. Validate uncertain user input before converting; never assume every string is numeric.
What does type() show?
type(value) displays the Python type, such as <class 'str'> or <class 'int'>. You may later see type(value).__name__: it retrieves only the name str or int from that type. The double underscores are part of Python's built-in metadata. You don't need that attribute to solve this lesson.
port_text = "443"
port_number = int(port_text)
print(type(port_text))
print(type(port_number))
print(port_number + 1)Why does the last line print 444, but port_number still stores 443? Reveal explanation after you predict.
port_number stores integer 443. type(port_text) prints the type str, and type(port_number) prints int (shown as class names). The final print calculates 443 + 1 without changing port_number.
Put variables into readable text
A useful script often needs one sentence containing both text and variable values. In Python, an f-string starts with f immediately before a quoted string. Place an expression inside curly braces to insert its current value. Python evaluates what is inside the braces before printing. This is how we can create device reports without accidentally trying to add text and numbers together.
Read the f-string out loud
f'{device}: {ports} ports online' means: insert device, print a colon and space, insert ports, then write the remaining text. An f-string can contain numbers without manual str() conversion.
Compare literal text with substituted values
print('{device}') outputs the literal braces and name. print(f'{device}') replaces the braces with the variable's value. A missing variable inside braces raises NameError.
device = "SW-01"
ports_online = 4
print(f"{device}: {ports_online} ports online")
print("{device}")What prints on each line? Why does only the first string show the hostname? Reveal explanation after you predict.
The first line is SW-01: 4 ports online. The second is the literal text {device}, because it has no leading f. The first f-string evaluates both expressions inside braces before printing.
Track assignment, not just output
The equals sign assigns a value. It does not assert mathematical equality. Each subsequent assignment updates the variable, and later statements use its most recent value. Trace this sequence line by line to see the difference.
Assignment is not comparison
count = 4 stores 4. count == 4 compares the value with 4 and produces a Boolean.
Augmented assignment
count += 2 is a shorter way to write count = count + 2. It updates count using the previous value.
ports_online = 4
ports_online += 2
ports_online = ports_online - 1
print(ports_online)What is the final value? Reveal explanation after you predict.
5: four, then six, then five.
Write the condition before the decision
Before writing if, make sure you can form an expression that returns True or False. Comparisons such as >, >=, == and != allow a script to evaluate the evidence rather than relying on a hard-coded answer.
Comparisons yield bool
latency_ms > 150 evaluates to True or False. Comparing strings with numbers raises TypeError; normalize the data type first.
Combine conditions
and requires both conditions to be true; or needs at least one; not reverses a Boolean. Parentheses clarify longer expressions.
latency_ms = 185
threshold_ms = 150
needs_attention = latency_ms > threshold_ms
print(needs_attention)What happens when latency_ms becomes 85? Reveal explanation after you predict.
The expression becomes False because 85 is not greater than 150.
Only then add if and else
An if statement executes an indented block only when its condition is truthy. An else block handles the other branch. Colons and indentation are part of Python syntax, not decoration.
Branching
If status != "online", run the investigation branch. Otherwise, print Healthy. Only one branch executes.
Edge cases
Test both sides of your threshold. For >= 5, the value 5 counts; for > 5, it does not. Boundaries cause real automation defects.
status = "offline"
if status != "online":
print("Investigate")
else:
print("Healthy")Which line prints if status is online? Reveal explanation after you predict.
Healthy; the inequality is False, so else runs.
When code fails, use the evidence
Errors are feedback about what Python tried to do. A SyntaxError often points to structure; a NameError to a missing name; a TypeError to an unsupported operation. Read the error and test a small hypothesis instead of rewriting everything.
Use the line number
Look for the line inside your own file shown in the traceback. The error often points to the operation that failed, even if the original bad value came earlier.
Output isn't proof of correctness
A script can run without errors yet produce the wrong answer. Compare actual output and variable types with the stated requirement and edge cases.
ports_text = "4"
# Fix the conversion before doing arithmetic
ports_total = int(ports_text) + 2
print(ports_total)What would happen if int(ports_text) were removed? Reveal explanation after you predict.
The expression "4" + 2 would raise TypeError because str and int cannot be added together.
Turn a requirement into Python
A technician often starts with words rather than code: 'Count online ports and print a short report.' Translate that request into named values, an expression, an output format and a small test. Try the first exercise below without opening a solution.
Identify inputs
Separate what is given (device name, port count) from what you must compute or display.
Define success
Know what the output must look like, including spaces, punctuation and the expected data types. Then modify the starter code and run it.
device_name = "SW-01"
ports_online = 4
print(device_name)Does this program meet a requirement to print 'SW-01: 4 ports online'? Reveal explanation after you predict.
No. It runs successfully but omits the port count and formatting.
Write your first working status report
You've seen the concepts in isolation. Now work from a requirement instead of a completed program. Use the editor, run actual Python, and step through variables until you can explain the result. The starter intentionally does not satisfy the task.
Write it. Run it. Understand it.
Real Python execution, a variable trace and feedback against the requirements. You write the code—answers aren't revealed up front.
A readable device report
Northstar needs a one-line status label. Use the existing variables to print the device name followed by a colon, a space, the count, and 'ports online'. Match the punctuation exactly.
SW-01: 4 ports onlineTry solving it before asking for help. Hints never show a completed program.
Your printed output and errors will appear here.
Run the code, then step through the executed lines to watch variable values change.
Now complete Python Fundamentals Practice.
This is the next step in the Python Fundamentals learning path—not an optional collection of unrelated activities. Complete the five coding challenges, including the type conversion and troubleshooting tasks, before moving on to the next written lesson.
Start the next milestone: Python Fundamentals Practice →Reference material
You don't need to memorize everything. Learn how to read the Python documentation and use it when a behavior is unfamiliar.
