πŸ”„ Quick Recap (Dayβ€―2)

  • You installed Pythonβ€―3 and verified it works.

  • You set up VS Code with the Python extension.

  • You ran your first script (hello.py) to confirm everything is ready.

🎯 What You’ll Learn Today

  1. How to display text on the screen with print().

  2. Why indentation matters in Python.

  3. How to write comments to explain your code.

Imagine Python is like talking to your computer. The print() command is how you speak aloud so the computer shows your words on the screen.

  • print(): Tells Python to display whatever is inside the parentheses and quotes.

  • Quotation marks: You must wrap text in " " or ' ' so Python knows it’s a message, not code.

Indentation

Python uses spaces at the start of a line to organize code into blocks. Even if you don’t use loops or functions today, it’s good to know:

  • Indentations best practices: The official Python style guide (PEPβ€―8) recommends using 4 spaces per indent level. It’s a balance between readability and compactness: fewer spaces can make nested blocks hard to distinguish, while too many spaces push code too far to the right.

  • Consistency matters: Always use spaces (not tabs) and stick to 4 spaces, so your code looks the same in any editor and avoids mixing tabs and spaces (which can cause errors).

Comments

Comments are notes you leave in your code. They start with # and are ignored by Python:

# This is a comment and will not run
print("Hello, Python!")  # This prints text

Comments help you remember what each part of your code does.

Your First Commands

  1. Open hello.py in VS Code.

  2. Replace its contents with:

    # hello.py
    print("Hello, World!")
    print("Learning Python is fun!")
  3. Save and run in the terminal:

    python hello.py
  4. You should see:

    Hello, World!
    Learning Python is fun!

πŸ§™β€β™‚οΈ Take the Wand and Try Yourself

  1. Create a new file called favorite.py.

  2. Add two print() commands:

    • One to display your favorite food.

    • One to display your favorite hobby.

  3. Add a comment at the top describing what the program does.

  4. Run favorite.py and check you see your two messages.

Expected output (example):

# favorite.py
Pizza
Reading books

Once you see your messages, congratulationsβ€”you’ve mastered printing text and comments! Ready for Day 4: Variables & Data Types? Let’s go!

Keep Reading