Lab 01: Hello World & Python Basics

🎯 Objective

Write and run your first Python program, understand the Python interpreter, and learn the basic building blocks of the language.

πŸ“š Background

Python is an interpreted, high-level programming language created by Guido van Rossum in 1991. It's now the world's most popular language for data science, web development, and automation. Python code reads almost like English β€” making it ideal for beginners and experts alike.

⏱️ Estimated Time

20 minutes

πŸ“‹ Prerequisites

  • None β€” this is your first lab!

πŸ› οΈ Tools Used

  • Python 3.12

πŸ”¬ Lab Instructions

Step 1: Your First Python Program

πŸ“Έ Verified Output:

πŸ’‘ print() is Python's built-in function for output. Unlike C or Java, no semicolons β€” Python uses newlines to end statements.

Step 2: Comments

πŸ“Έ Verified Output:

Step 3: Python as a Calculator

πŸ“Έ Verified Output:

πŸ’‘ / always returns float in Python 3. Use // for integer division. ** is the power operator.

Step 4: Variables

πŸ“Έ Verified Output:

πŸ’‘ Python is dynamically typed β€” no need to declare types. f"..." is an f-string for embedding variables in text.

Step 5: Multiple Assignment and Swap

πŸ“Έ Verified Output:

Step 6: Print Function Options

πŸ“Έ Verified Output:

Step 7: Getting System Info

πŸ“Έ Verified Output:

Step 8: Python's Philosophy

πŸ“Έ Verified Output:

πŸ’‘ Both work, but Python style (PEP 8) uses spaces around operators and one statement per line. Readable code is maintainable code.

βœ… Verification

🚨 Common Mistakes

  • Mixing tabs and spaces β€” use 4 spaces consistently

  • Print() vs print() β€” Python is case-sensitive

  • 5/2 returns 2.5 not 2 β€” use 5//2 for integer division

  • Forgetting quotes around strings: name = Alice β†’ NameError

πŸ“ Summary

  • print() outputs to the terminal; # starts a comment

  • Variables assigned with =; no type declarations needed

  • Core types: int, float, str, bool

  • f-strings f"{value}" are the modern formatting standard

  • Python enforces readability β€” clean code is Pythonic code

πŸ”— Further Reading

Last updated