Learn Python basics with beginner-friendly tutorials, examples, and exercises. Master Python programming concepts like print function, variables, comments, indentation and more. Perfect for students and professionals starting their Python journey.
web development
, data science
, machine learning
, and automation
.PyCharm
, or even a simple text editor like Notepad
.Important: Python source code files always use the
.py
extension.
There are two main types of comments in Python:
# This is a single-line comment
print("Hello, World!")
"""
This is a multi-line comment.
It can span multiple lines of code.
"""
print("Hello, World!")
See also:
In Python, indentation refers to the use of whitespace (spaces or tabs) to denote block-level structure in the code. Python uses indentation to define the scope of code blocks, such as:
In Python, indentation is mandatory and is used to determine the grouping of statements. The number of spaces used for indentation is not fixed, but it’s standard to use 4 spaces for each level of indentation. Read more: Indentation - PEP 8 – Style Guide for Python Code
Here’s an example:
if True:
print("Hello") # This line is indented with 4 spaces
print("World") # This line is also indented with 4 spaces
In this example, the two print statements are indented with 4 spaces, indicating that they are part of the if block.
Python’s indentation system has several benefits, including:
Another example, consider the following code snippet:
if True:
print("True")
else:
print("False")
Task: 15 Please correct the following Python code:
if True:
print("True")
print("False")
Error message: IndentationError: unexpected indent
”
See also:
Title: “Teach Your Team”
Instructions:
💡 Key Learning Points:
✔ Leadership through teaching.
✔ Confidence in public speaking.
✔ Understanding Python better by explaining it.
✅ Online Quizzes for Python Basics