Your First Python Script – Getting Started the Right Way
Right, so you’ve got Python installed and working. Brilliant. Now comes the bit where most tutorials go completely wrong – they immediately want you creating files and writing complex programs.
Bollocks to that. Let’s start properly.
Python for Network Engineers Blog 2: Installing Python
Your first python script experience should be about understanding what Python actually does when you give it commands. And the best way to learn that is by talking to Python directly, not by creating files you don’t understand yet.
We’re going to start with Python’s interactive shell – the REPL – then move to creating your first actual script file. This way you understand what’s happening before you start worrying about file management.
Starting with the Python REPL
The REPL stands for Read-Evaluate-Print-Loop, but don’t worry about that acronym. Just think of it as having a conversation with Python. You type something, Python responds, you type something else, Python responds again.
This is perfect for your first python script experience because you get immediate feedback. No creating files, no wondering if something worked – you type a command and see the result straight away.
Opening the Python REPL
Right, let’s get started. Open your Command Prompt (on Windows) or terminal (on Linux) and type:
python
You’ll see something like this:
PS C:\Users\kille> python
Python 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
That >>>
is Python waiting for you to tell it what to do. This is the Python prompt – your direct line to the Python interpreter.
Your First Python Commands
Let’s start with something simple. Type this at the >>>
prompt:
>>> print("Hello Python!")
Hit Enter and Python responds:
Hello Python!
>>>
There you go – you’ve just executed your first Python command! Python read what you typed, evaluated it (figured out what print does), printed the result, then looped back to wait for your next command.
Let’s try a few more:
>>> print("SW1-ACCESS")
>>> print("R1-EDGE-RTR")
>>> print("Network device names")
Each time you hit Enter, Python executes that line immediately and shows you the result.
Understanding Immediate Execution
This is the brilliant thing about Python’s REPL – everything happens immediately. No compilation, no waiting, no complex setup. You type a command, Python does it.
Try some basic calculations:
>>> 24 + 48
72
>>> 100 - 23
77
>>> 10 * 5
50
See how Python calculates the result and shows it immediately? This instant feedback is perfect for learning.
Working with Text
Let’s try some text operations using networking examples:
>>> "SW1" + "-" + "ACCESS"
'SW1-ACCESS'
>>> "VLAN " + "10"
'VLAN 10'
>>> "GigabitEthernet" + "0/1"
'GigabitEthernet0/1'
The +
operator joins text together. Python calls this concatenation.
Creating Simple Variables
Now let’s try storing information in variables. Don’t worry – we’ll cover variables properly in a later lesson. For now, just understand that variables let you give names to pieces of information:
>>> hostname = "SW1-ACCESS"
>>> hostname
'SW1-ACCESS'
>>> print(hostname)
SW1-ACCESS
When you type just the variable name, Python shows you what’s stored in it. When you use print(), it displays the content without the quotes.
Try a few more:
>>> device_type = "Switch"
>>> location = "Building A"
>>> device_type
'Switch'
>>> print(location)
Building A

Understanding the REPL’s Behaviour
The REPL has some specific behaviours that are worth understanding for your first python script experience.
Expressions vs Statements
When you type an expression (something that has a value), the REPL shows you the result:
>>> 24 + 48
72
>>> "SW1-ACCESS"
'SW1-ACCESS'
>>> hostname
'SW1-ACCESS'
When you type a statement (something that does an action), the REPL just does it:
>>> print("Hello")
Hello
>>> hostname = "R1-EDGE-RTR"
>>>
Notice how print()
shows the output, but creating a variable doesn’t show anything – it just does the assignment.
Multi-line Input
Sometimes you’ll type something that isn’t complete, and Python will wait for more:
>>> print("This is a long
...
Those ...
dots mean Python is waiting for you to finish. Just complete the line:
>>> print("This is a long message")
This is a long message
For now, keep everything on single lines to avoid confusion.
Getting Out
To exit the REPL and get back to your command prompt, type:
>>> exit()
Or press Ctrl+D (Linux/Mac) or Ctrl+Z then Enter (Windows).
Moving to Your First Script File
Right, so you’ve had a play with the REPL and understand how Python executes commands. Now let’s create your first actual Python script file.
The REPL is brilliant for trying things out, but everything disappears when you close it. Script files let you save your commands so you can run them again later.
Creating Your First File
Open your text editor (IDLE, VS Code, or even Notepad) and create a new file. Save it as my_first_script.py
in a folder you can find easily.
The .py
extension tells your computer this is a Python file.
Now type this into the file:
# My first Python script
print("Network Device Information")
print("Device: SW1-ACCESS")
print("Type: Switch")
print("Location: Building A")
Save the file.
Understanding Comments
The line starting with #
is a comment. Python ignores comments completely – they’re for humans to read. Comments explain what your code does.
Always start your scripts with a comment explaining what they do. When you come back to the file in six months, you’ll thank yourself.
Running Your Script
Open Command Prompt and navigate to where you saved your file. Then type:
python my_first_script.py
You should see:
Network Device Information
Device: SW1-ACCESS
Type: Switch
Location: Building A
Congratulations! You’ve just created and run your first python script file.
Script vs REPL – What’s the Difference?
In the REPL, you type commands one at a time and see results immediately. In a script file, Python reads all the commands first, then executes them from top to bottom.
REPL:
>>> print("First")
First
>>> print("Second")
Second
Script file:
print("First")
print("Second")
Output when you run the script:
First
Second
Same result, but the script runs all at once.
Understanding Execution Order
This is crucial for your first python script – Python executes commands in the order you write them, from top to bottom.
Try this in the REPL:
>>> print("This runs first")
This runs first
>>> print("This runs second")
This runs second
>>> print("This runs third")
This runs third
Same thing happens in script files. Create a file called order_test.py
:
print("Step 1: Starting device check")
print("Step 2: Checking SW1-ACCESS")
print("Step 3: Device online")
print("Step 4: Check complete")
When you run it, you’ll see the messages in exactly that order.
This seems obvious, but it’s fundamental to programming. Your commands execute in sequence, one after another.
Working with Simple Data
Let’s expand your first python script to handle some basic information. Create device_info.py
:
# Simple device information script
print("Device Information Display")
print("=" * 30)
hostname = "SW1-ACCESS"
print("Hostname:")
print(hostname)
location = "Building A"
print("Location:")
print(location)
print("Script complete")
This introduces a few new concepts:
String repetition: "=" * 30
creates a line of 30 equals signs. The *
operator repeats the character.
Variable assignment: hostname = "SW1-ACCESS"
stores the text in a variable called hostname.
Variable usage: print(hostname)
displays whatever is stored in the hostname variable.
Run this script and see how it works.
Common Beginner Mistakes
Let me tell you about the mistakes I see people make with their first python script.
Mistake 1: Forgetting Quotes
# Wrong - Python thinks SW1-ACCESS is a command
print(SW1-ACCESS) # NameError
# Right - quotes make it text
print("SW1-ACCESS")
Without quotes, Python thinks you’re referring to a variable or command. With quotes, it knows you mean the actual text.
Mistake 2: Mixing REPL and Script Syntax
In the REPL, you see the >>>
prompt:
>>> print("Hello")
But in script files, you don’t include the >>>
:
# Right - script file
print("Hello")
# Wrong - don't include the prompt
>>> print("Hello")
The >>>
is just the REPL’s prompt, not part of Python syntax.
Mistake 3: Not Saving Files
Create your script, run it, get an error about file not found. You forgot to save the file after editing it. Always save before running.
Mistake 4: Wrong File Location
Save your script in one folder, try to run it from another folder. Python can’t find the file. Make sure you’re in the right directory when you run python filename.py
.
Debugging Your First Script
When your first python script doesn’t work (and it won’t always), here’s how to figure out what’s wrong.
Read Error Messages
Python gives you helpful error messages. Don’t just panic – read what it says:
print("Hello"
# SyntaxError: unexpected EOF while parsing
This tells you exactly what’s wrong – you forgot the closing parenthesis.
Check Line by Line
If your script isn’t doing what you expect, go back to the REPL and test each line individually:
>>> print("Device Information")
Device Information
>>> hostname = "SW1-ACCESS"
>>> print(hostname)
SW1-ACCESS
This helps you find which line is causing problems.
Use Simple Print Statements
Add print statements to see what’s happening:
print("Script starting")
hostname = "SW1-ACCESS"
print("Hostname set")
print(hostname)
print("Script ending")
This shows you exactly how far your script gets before any problems occur.
Building Good Habits Early
Your first python script should establish good habits that will help you later.
Use Descriptive Names
# Good - clear what this represents
hostname = "SW1-ACCESS"
# Poor - unclear what 'x' means
x = "SW1-ACCESS"
Add Comments
# Display device information
print("Device: SW1-ACCESS")
print("Status: Online") # Device is operational
Keep It Simple
Don’t try to do too much in your first python script. Focus on understanding how Python executes commands and how scripts work.
Test Frequently
Don’t write 50 lines then try to run them. Write a few lines, test, add more, test again.
Comparing REPL and Script Workflows
Understanding when to use the REPL versus script files is important for your first python script experience.
Use the REPL When:
- Learning new commands
- Testing ideas quickly
- Doing quick calculations
- Experimenting with syntax
Use Python Script Files When:
- You want to save your work
- Running the same commands repeatedly
- Creating something others will use
- Building larger programs
Typical Workflow:
- Try ideas in the REPL
- Once they work, put them in a script file
- Run the script to test everything together
- Go back to REPL to fix problems
Expanding Your Python Script Gradually
Once you’re comfortable with basic scripts, you can gradually add more functionality. But keep it simple for now.
Try creating improved_device_info.py
:
# Improved device information display
print("Network Device Inventory")
print("=" * 25)
# Device 1
device1 = "SW1-ACCESS"
type1 = "Switch"
print("Device 1:")
print(device1)
print(type1)
print()
# Device 2
device2 = "R1-EDGE-RTR"
type2 = "Router"
print("Device 2:")
print(device2)
print(type2)
print()
print("Inventory complete")
This uses concepts you already understand but organizes them better. The empty print()
adds blank lines for spacing.
Understanding File Management for your Python Script
As you create more Python scripts, you’ll need to organize them properly.
File Naming
Use descriptive names with underscores:
device_info.py
✓network_check.py
✓script1.py
✗temp.py
✗
File Organization
Create a folder for your Python scripts:
python_scripts/
├── my_first_script.py
├── device_info.py
├── order_test.py
└── improved_device_info.py
Running Scripts from Different Folders
If your script is in a different folder, either:
- Navigate to that folder first, then run
python script_name.py
- Or specify the full path:
python C:\path\to\script_name.py

Next Steps After Your First Script
You’ve successfully created and run your first python script. You understand the difference between the REPL and script files, how Python executes commands in order, and how to debug basic problems.
You’re ready to learn more Python fundamentals like:
- How to write better comments (covered next)
- Understanding Python’s indentation rules
- Working with different types of data
- Making decisions in your code
- Repeating actions efficiently
But for now, practice what you’ve learned. Try creating a few simple scripts using device names, interface descriptions, or VLAN information. Get comfortable with the basic workflow of writing code, saving files, and running them.
Your first python script experience should build confidence, not confusion. You understand how Python works, how to interact with it through the REPL, and how to create simple script files that do useful things.
This foundation prepares you for everything else you’ll learn about Python programming. You’re not just copying code – you understand what happens when Python runs your commands and why scripts work the way they do.
External Link: Python REPL Tutorial – official documentation about using Python’s interactive interpreter
Pingback: Python for Network Engineers Blog 4: Python Print Function - RichardKilleen