-
๐ฏ Learning Objectives:
By the end of this lesson, learners will be able to:
-
Write and run a basic Python script
-
Understand how
print()
works -
Learn Python’s indentation rules and syntax basics
-
Understand how code is executed in Python
๐ Lesson Content
๐น Introduction to Python Syntax
Python is known for its clean and readable syntax. You don’t need to add semicolons or curly braces to structure your code โ indentation (tabs/spaces) is what defines code blocks.
๐ง Simple Rule: One level of indentation = 4 spaces or 1 tab.
๐ธ Your First Python Program
Letโs write the most basic Python program:
๐ This line does the following:
-
print()
is a built-in function used to display output. -
"Hello, World!"
is a string inside double quotes. -
When you run this, Python will display:
Hello, World!
๐ธ How to Run Your Python Program
Option 1: Using a Code Editor (e.g., VS Code)
-
Open your code editor
-
Create a new file:
first_program.py
-
Type the code:
-
Save the file and run it using:
-
Terminal:
python first_program.py
-
OR use the Run button in the editor
-
Option 2: Using Online Editors
Try it online if Python is not yet installed:
โ ๏ธ Understanding Python Indentation
Try this code:
This will give an IndentationError.
Python relies on indentation to define the structure of code (like loops, functions, etc.). This strict indentation rule helps write cleaner, readable code.
๐ก More Practice:
Write the following code to try printing multiple lines:
๐ Assignment
-
Create and run a file called
first_program.py
-
Print three different statements using the
print()
function -
Try adding incorrect indentation and observe the error
-
About Lesson