Learn Python: The Fundamentals

Now that you’ve got Python installed and ready to go, let’s talk about two things you absolutely need to get right from the start — syntax and indentation.

 

Think of syntax like the grammar rules of Python. It’s how you tell Python exactly what you want it to do. And just like grammar in writing, if you mess up the structure — like forgetting a quote or placing something in the wrong spot — Python won’t get it. Instead, it’ll stop and throw an error.

 

Here’s a line that works just fine:

print("Hello, World!")

 

But if you forget to close the quotation marks, like this:

print("Hello, World!)

 

Python will have no clue what you’re trying to say and hit you with a SyntaxError.

 

Now let’s talk about indentation — and this is where Python is a bit more strict than other languages. In most programming languages, indentation is optional and mostly just for looks. But in Python? It’s not optional. It’s how the language knows what belongs to what.

 

Let’s take a look at an example that’s correctly indented:

if 5 > 2:
    print("Five is greater than two")

 

See that space before print? That tells Python, “Hey, this print statement is part of the if block.”

 

Now watch what happens when you remove the indentation:

if 5 > 2:
print("Five is greater than two")

 

Boom — IndentationError. Python doesn’t know where the block starts and ends, so it stops running your code.

 

Basic Print Function Exercise

Let’s practice the print function real quick. Run the code below, then try changing the message and run it again.

 


# Try changing the message inside the print function
print("This is a simple message!")

 
Edit the text inside the parentheses and run it again.

 

Getting comfortable with Python’s syntax and indentation early on will save you tons of time later. It keeps your code clean, readable, and working — and that’s what you want.