Your First Python Program: Print, Comments, and Syntax Basics

Just starting out with Python? This beginner-friendly guide walks you through writing your very first Python program. Learn how to use the print() function, add comments, and understand basic syntax with easy-to-follow examples. Perfect for first-time coders looking to build a solid foundation.

Welcome to Your First Python Program

So you’ve installed Python, set up your code editor, and are ready to start coding. First off - well done. That first setup step is where many people stop. But you’re going further, and that’s awesome.

In this guide, you’ll write your very first Python program and learn about three foundational concepts that every Python developer uses:

  • Displaying output with print()
  • Writing helpful comments
  • Understanding Python’s clean and simple syntax

Whether you're a student, an aspiring developer, or just curious about coding, this guide is designed to make your first step smooth, practical, and confidence-building.


Why This Matters

Most coding tutorials jump into complex topics too fast. But understanding these three fundamentals - print(), comments, and syntax - will save you hours of confusion down the road.

They’re like learning how to write your name before composing full sentences. So let’s keep it simple, clear, and hands-on.


Step 1: Create a Python File

Before we write any code, we need a place to put it.

  1. Open the folder you created earlier (e.g., python-projects/hello-python) in VS Code.
  2. Create a new file and name it main.py.
  3. This is where your Python code will live.

Make sure VS Code is set to use Python (you should see the Python interpreter selected in the bottom bar).


Step 2: Display Your First Message with print()

Let’s write the most classic program ever:

print('Hello, world!')

To run your program:

On macOS/Linux:

python3 main.py

On Windows:

python main.py

If everything's working correctly, you'll see:

Hello, world!

🧠 What Just Happened?

  • print() is a built-in Python function.
  • 'Hello, world!' is a string - a piece of text inside quotes.
  • When you run your script, Python interprets the line and prints the message to your terminal.

Step 3: Add Comments to Explain Your Code

Now let’s make your code easier to understand — for your future self and anyone else who reads it.

# This is a comment
print('Hello, world!')  # This prints a greeting

✔️ Rules of Comments:

  • Anything after # is ignored by Python
  • Use them to explain why you’re doing something
  • Don’t comment every line, just the ones that need clarity

Think of comments as whispers to other humans reading your code. They're essential, especially as your code grows more complex.


Step 4: Understand Basic Python Syntax

Python is famous for being readable, but it has its own rules. Here are three that matter most at this stage:


1. Indentation Is Mandatory

Python uses indentation to define blocks of code. This means spaces at the beginning of a line matter.

if True:
    print('This is indented correctly')

If you don’t indent properly, Python will throw an IndentationError.

Most editors (like VS Code) use 4 spaces per indent. Stick with that and you’ll be fine.

2. Python Is Case-Sensitive

These are not the same:

print('hi')    # ✅ works
Print('hi')    # ❌ error

Always use lowercase for Python’s built-in functions.


3. No Semicolons Required

Unlike C, Java, or JavaScript, Python doesn’t need a semicolon at the end of each line.

print('Clean and simple')  # No semicolon needed

You can use semicolons, but Pythonistas avoid them.


Step 5: Try It Yourself - A Mini Challenge

Here’s a quick exercise. Write a Python script that:

  1. Prints your name
  2. Prints your age
  3. Prints your favorite hobby
  4. Includes comments for each section

Example:

# Print basic personal info
print('Name: Abhay')
print('Age: 24')
print('Hobby: Coding and music')

Run your program. Did it work? Great! You just created your first personal output script.


Bonus: Print Different Data Types

Python can handle different kinds of data - not just text.

print(42)               # Integer
print(3.1415)           # Float
print(True)             # Boolean
print('Age:', 24)       # Combining string and number

You’ll soon learn how to store and manipulate these values using variables.


✅ Recap: What You Learned Today

You now know how to:

  • Create and run a Python file
  • Use the print() function
  • Add comments for clarity
  • Follow basic Python syntax rules

You’ve written real Python code. That’s more than most people ever do.


🚀 Where to Go from Here

Now that you’ve taken your first steps, here’s what to explore next:

  • Variables - store and reuse data
  • Data types - strings, numbers, booleans, and more
  • Input - allow users to enter data
  • Control flow - use if, else, and elif to make decisions
  • Loops - repeat actions with for and while

🙌 Final Thoughts

Learning to code is less about being perfect and more about showing up, trying, and not being afraid to make mistakes.

You’ve written your first program. That makes you a programmer.

So keep going - ask questions, experiment, and most importantly, have fun.
Welcome to the world of Python.

Happy coding! 🐍