Your First Python Program
Write and run your first Python programs! Master print statements, comments, and basic syntax rules.
Write and run your first Python programs! Master print statements, comments, and basic syntax rules. This hands-on tutorial focuses on practical implementation of your first python program concepts.
Your First Python Program
Let's write real Python code! In this lesson, you will create your first programs and learn the fundamental syntax that powers everything in Python.
The Classic: Hello, World!
Every programmer's journey starts here. This simple program verifies that your environment is set up correctly.
Understanding print()
The print() function is more powerful than it looks. It can handle multiple items, custom separators, and line endings.
1. Printing Multiple Items
You can print multiple values by separating them with commas. Python automatically adds a space between them.
2. The sep Argument (Separator)
By default, items are separated by a space. You can change this using sep.
3. The end Argument (End of Line)
By default, print() adds a new line (\n) at the end. You can change this using end.
Comments: Notes for Humans
Comments are lines of code ignored by Python. They are crucial for explaining why you wrote code a certain way.
Single-Line Comments
Start with a hash symbol #.
Multi-Line Comments (Docstrings)
Use triple quotes """ or '''. Technically these are strings, but they are often used as multi-line comments.
Python Syntax Rules
1. Indentation Matters!
Python uses indentation (spaces) to define blocks of code. Other languages use curly braces {}.
[!WARNING] Indentation Error: If you indent code when you shouldn't, or don't indent when you should, Python will crash.
2. Case Sensitivity
print is not the same as Print. Variables age, Age, and AGE are all different.
Common Beginner Mistakes
| Mistake | Example | Fix |
|---|---|---|
| Missing Quotes | print(Hello) | print("Hello") |
| Mismatched Quotes | print("Hello') | print("Hello") |
| Capitalizing Commands | Print("Hi") | print("Hi") |
| Unexpected Indent | print("Hi") | print("Hi") (remove spaces) |
AI Mentor
Confused about "Python syntax rules indentation and comments"? Ask our AI mentor for a simplified explanation.
Quiz
Quiz
Question 1 of 5What does the 'sep' argument do in print()?
Key Takeaways
✅ print(a, b, sep="-") customizes separators.
✅ print(a, end=" ") prevents a new line.
✅ Comments (#) explain code and are ignored by Python.
✅ Indentation defines code blocks and must be consistent.
✅ Python is case-sensitive.
What's Next?
Now that you can print and comment, let's learn how to store data! In the next lesson, we'll cover Variables & Data Types.
Keep coding! 🚀