How to Create a Simple Python Code (Step-by-Step Guide)

Last updated on November 12, 2025

Laptop screen showing Python code editor with a simple program running in the terminal.

I still remember the first time I tried Python — I had no idea what I was doing. I typed a few lines, pressed “Run,” and somehow the program actually worked. That little win felt huge. Honestly, that’s the beauty of Python — it’s beginner-friendly, forgiving, and surprisingly fun to learn.Whether you’re trying to get into programming, automate small tasks, or just understand what all the fuss is about, Python is the perfect place to start. And the best part? You don’t need any fancy setup to write your first code. I’ll walk you through everything step-by-step, like we’re figuring it out together.

What You’ll Need

  • A computer (Windows, macOS, or Linux — anything works).
  • Python installed (version 3 or higher is best).
  • A text editor — you can use IDLE (which comes with Python), VS Code, or even Notepad.

That’s it. No complex setup, no confusing tools. Just you, your computer, and a little curiosity.

Step 1 — Install Python (If You Haven’t Already)

Go to the official Python website and click “Download Python.” The site automatically detects your system, so you’ll get the right version.

Once downloaded, open the installer and make sure you tick the box that says:

Add Python to PATH

This small step saves you from a lot of headaches later when you try running Python from your command line.

After installation, open your terminal or command prompt and type:

python --version

If you see something like Python 3.11.0, congratulations — it’s installed correctly.

Step 2 — Open Your Text Editor or IDE

Python comes with an editor called IDLE. You can find it in your applications after installation. But if you want something more powerful, I highly recommend using VS Code.

Once you’ve got your editor open, create a new file and save it as first_program.py. The .py extension tells your computer it’s a Python file.

Step 3 — Write Your First Python Code

Let’s start simple. Inside your first_program.py file, type this:

print("Hello, World!")

Save it, then run the file. If you’re using IDLE, just hit Run → Run Module.
If you’re using VS Code or the terminal, open your terminal and type:

python first_program.py

You should see this output:

Hello, World!

That’s your first Python program — simple, clean, and working. Feels good, doesn’t it?

Step 4 — Learn the Basics: Variables and Data

Python is all about simplicity. You don’t have to declare variable types like other languages — you just name them and go.

name = "Alice"
age = 25
height = 1.68

You can then combine them in a sentence using the print() function:

print(name, "is", age, "years old and", height, "meters tall.")

Output:

Alice is 25 years old and 1.68 meters tall.

Pretty intuitive, right? You can use text, numbers, or even store lists of items — all without too much setup.

Step 5 — Add Some Logic (If and Else)

Let’s say you want your program to respond differently based on input. Python’s if statements make this super easy:

age = int(input("Enter your age: "))

if age >= 18:
    print("You're an adult!")
else:
    print("You're still a minor!")

When you run this, Python will ask for your age and respond accordingly.
Notice how the indentation (the spaces before print) matters — it’s how Python knows what’s inside the “if” and “else.”

Step 6 — Use Loops

Loops let you repeat tasks easily. For example, if you want to print numbers 1 through 5:

for i in range(1, 6):
    print(i)

Output:

1
2
3
4
5

Simple and neat. You can also use while loops if you want something to keep running until a condition is met.

Step 7 — Create a Simple Function

Functions let you organize your code better and reuse it whenever you need. Let’s write one that greets someone:

def greet(name):
    print("Hello,", name, "! Welcome to Python programming.")

greet("Alice")
greet("John")

When you run it, you’ll see:

Hello, Alice! Welcome to Python programming.
Hello, John! Welcome to Python programming.

Functions keep your code clean and flexible — and once you start using them, there’s no going back.

Step 8 — Handle Errors Gracefully

No matter how careful you are, errors happen. Python lets you handle them without crashing your entire program:

try:
    number = int(input("Enter a number: "))
    print("You entered:", number)
except ValueError:
    print("That’s not a valid number!")

This way, your program keeps running even if the user types something unexpected.

Step 9 — Save and Run Like a Pro

Once you’re comfortable running small snippets, try saving multiple files in one folder. You can import functions between files using the import keyword:

# In greet.py
def say_hello():
    print("Hello there!")

# In main.py
import greet

greet.say_hello()

This is how real-world Python projects are structured — small, readable files working together.

Step 10 — Keep Learning (One Small Step at a Time)

Once you’ve mastered the basics, the world opens up. You can learn Python for:

  • Data analysis using Pandas and NumPy.
  • Web development using Flask or Django.
  • Automation — writing scripts that handle boring repetitive tasks.

There’s always something new to learn, but the key is to keep coding. Even if it’s just 10 minutes a day — that’s how you build real skill.

Final Thoughts

Python is one of those languages that feels like it was made to help you succeed. It doesn’t punish mistakes — it teaches you through them. And the first time you make something work all by yourself? That little spark of pride? Yeah, it’s addictive.

So go ahead — open your editor, type a few lines, and press run. Your first Python project is waiting for you.

How to Create a Simple Python Code (Step-by-Step Guide)
Share this⬇️
Scroll to top