DEV Community

Cover image for Your First Python Program Runs. Now What?
Akhilesh
Akhilesh

Posted on

Your First Python Program Runs. Now What?

You downloaded Python. You watched the installation video. You followed along. You opened the terminal and typed that command.

And it worked.

"Hello, World!" appeared on the screen.

You stared at it for a second. Then you thought: okay, but what just happened? And what do I do now?

That's exactly where this post starts. Not from "let's learn programming theory." From the moment after it works, when the real questions begin. :contentReference[oaicite:0]{index=0}


What You'll Actually Get From This Post

By the time you finish reading and writing the code yourself, you'll know:

  • What Python actually is and what "running a program" means
  • How to create a Python file and run it from the terminal
  • What variables are and how to use them
  • The three most common beginner mistakes and how to fix them
  • How to use print() to see what's happening in your code

That's it. No loops. No functions. No classes. Just the foundation, done properly.


What Python Actually Is

Python is a language. Like English or Spanish, but for talking to computers instead of people.

Your computer only understands one thing at the deepest level: numbers. Specifically, zeros and ones. Everything your computer does, every app, every website, every video game, is ultimately zeros and ones being processed by hardware.

Writing zeros and ones directly would be insane. So over time, people invented layers on top. Assembly language. Then C. Then higher-level languages like Python. Each layer makes it easier for humans to write instructions, and something else handles translating those instructions into what the machine actually understands.

Python is one of the highest-level, most readable programming languages that exists. When you write Python, it reads almost like English. That's not an accident. It was designed that way.

When you "run a Python program," here's what actually happens:

  1. You write code in a .py file. It's just text. Plain text in a file that ends with .py.
  2. You tell Python to run that file.
  3. Python reads your file from top to bottom, line by line.
  4. It executes each line and produces output.

That's the whole model. Top to bottom. One line at a time. That's how Python thinks.


Setting Up: The Two Things You Need

You need two things installed: Python and a place to write code.

For writing code, use VS Code. It's free, it's what most developers use, and it makes Python easier to work with.

YT: How to install Python and VS Code for beginners 2024

Once both are installed, open VS Code. Open a folder somewhere on your computer where you'll keep your code. Something like ai_ml_journey in your Documents folder. Create a new file inside it. Name it lesson01.py.

The .py extension tells VS Code and your computer: this is a Python file.


Your First Real Program

Open lesson01.py and type this exactly. Don't paste it. Type it.

print("Hello, World!")
print("My name is Akhil")
print("I am learning Python")
Enter fullscreen mode Exit fullscreen mode

Save the file.

Now open your terminal (in VS Code you can press Ctrl + backtick on Windows/Linux, or Cmd + backtick on Mac). Type:

python lesson01.py
Enter fullscreen mode Exit fullscreen mode

Press enter. You should see:

Hello, World!
My name is Akhil
I am learning Python
Enter fullscreen mode Exit fullscreen mode

That's a program. Three instructions. Python reads the first line, executes it, prints the text. Then reads the second, executes it, prints. Then the third.

print() is a function. It takes whatever you put inside the parentheses and displays it on the screen. The text inside the quotes is called a string. More on that in the next post.

Change "Akhil" to your actual name if needed. Save. Run it again. See your name appear. That's your first customization of a program.


Variables: Storing Information

Every program needs to remember things. What's the user's name? What number did they enter? What was the result of a calculation?

Variables are how you store information and give it a name.

name = "Akhil"
age = 22
city = "Mumbai"

print(name)
print(age)
print(city)
Enter fullscreen mode Exit fullscreen mode

Run this. Output:

Akhil
22
Mumbai
Enter fullscreen mode Exit fullscreen mode

A variable is a name that points to a value. When you write name = "Akhil", you're telling Python: create a box, label it name, and put the value "Akhil" inside it. Later, when you write print(name), Python goes to the box labeled name, takes out what's inside, and prints it.

The = sign in Python doesn't mean "equals" the way it does in math. It means "assign." Put the right side into the box labeled on the left side.


Using Variables Together

Variables become powerful when you combine them.

name = "Akhil"
age = 22
city = "Mumbai"

print("My name is " + name)
print("I am " + str(age) + " years old")
print("I live in " + city)
Enter fullscreen mode Exit fullscreen mode

Output:

My name is Akhil
I am 22 years old
I live in Mumbai
Enter fullscreen mode Exit fullscreen mode

Notice str(age). The age variable holds a number, not text. When you try to combine a number and text with +, Python gets confused. str() converts the number into text so you can combine them. This is one of the most common errors beginners hit.

There's also a cleaner way to do this. Python has something called f-strings. They're easier to read and you'll use them constantly.

name = "Akhil"
age = 22
city = "Mumbai"

print(f"My name is {name}")
print(f"I am {age} years old")
print(f"I live in {city}")
Enter fullscreen mode Exit fullscreen mode

The f before the opening quote turns it into an f-string. Anything inside {} gets replaced with the value of that variable. Same output, cleaner code. Use f-strings.


Changing Variables

Variables can change. That's literally why they're called variables.

score = 0
print(f"Score: {score}")

score = 10
print(f"Score: {score}")

score = score + 5
print(f"Score: {score}")
Enter fullscreen mode Exit fullscreen mode

Output:

Score: 0
Score: 10
Score: 15
Enter fullscreen mode Exit fullscreen mode

Line 3 is interesting. score = score + 5 means: take the current value of score (which is 10), add 5 to it, and store the result back in score. So score becomes 15.

This pattern shows up constantly in programming. You'll use it for counters, running totals, tracking progress.


What Everyone Gets Wrong at the Start

Mistake 1: Forgetting quotes around text

name = Akhil
Enter fullscreen mode Exit fullscreen mode

Python sees Akhil without quotes and thinks it's a variable. It doesn't exist.

Error:

NameError: name 'Akhil' is not defined
Enter fullscreen mode Exit fullscreen mode

Fix:

name = "Akhil"
Enter fullscreen mode Exit fullscreen mode

Mistake 2: Mixing text and numbers without converting

age = 22
print("I am " + age + " years old")
Enter fullscreen mode Exit fullscreen mode

Error:

TypeError: can only concatenate str (not "int") to str
Enter fullscreen mode Exit fullscreen mode

Fix:

print(f"I am {age} years old")
Enter fullscreen mode Exit fullscreen mode

Mistake 3: Wrong indentation

Python uses indentation (spaces at the start of a line) to understand structure.

Error:

IndentationError: unexpected indent
Enter fullscreen mode Exit fullscreen mode

Fix: Remove extra spaces at the start.


A Full Working Example

first_name = "Akhil"
last_name = "Yadav"
age = 22
city = "Mumbai"
learning = "Python"

full_name = first_name + " " + last_name

print(f"Name: {full_name}")
print(f"Age: {age}")
print(f"City: {city}")
print(f"Currently learning: {learning}")
print(f"Goal: Become an AI engineer")
Enter fullscreen mode Exit fullscreen mode

Output:

Name: Akhil Yadav
Age: 22
City: Mumbai
Currently learning: Python
Goal: Become an AI engineer
Enter fullscreen mode Exit fullscreen mode

Notice full_name = first_name + " " + last_name. The " " adds a space between first and last name.


Try This Yourself

Create a new file called about_me.py.

Write a program that stores your real information:

  • name
  • age
  • city
  • interest
  • goal

Then print:

Hi, my name is [your name].
I'm [your age] years old and I live in [your city].
I'm interested in [your interest].
My goal is [your goal].
Enter fullscreen mode Exit fullscreen mode

Make everything come from variables.

Run it. Change a variable. Run again. Notice how output changes.


What's Next

The next post covers data types.

Right now you've been storing text and numbers without really understanding what's different about them.

And that difference matters more than it seems.

Top comments (0)