INSTACK 360

Python Syntax, Comments & First Program

Write your very first lines of Python code. Learn how Python structures code using indentation and how to leave helpful comments.

Beginner 5 min read

Your First Program

In the programming world, it's a tradition that your first program should simply greet the world. Let's do that using Python's built-in print() function.

print("Hello, World!")

That's it! No complex boilerplate, no classes needed just to print a line. Just pure, straightforward code.

The Golden Rule: Indentation

If you're coming from C++, Java, or JavaScript, you are used to curly braces {} defining blocks of code. Python does away with that clutter. Instead, it uses indentation (spaces or tabs).

if True:
    print("This is indented correctly.")
    print("This is part of the same block.")
print("This is outside the block.")

If you mess up the indentation, Python will angrily throw an IndentationError. It forces you to write clean, readable code.

Leaving Notes: Comments

Code tells the computer how to do something, but comments tell other humans (and your future self) why you did it. Use the hash # symbol for comments.

# Calculate the total price including tax
total = price * 1.20