When learning any programming language, it’s essential to master the fundamentals first. Python is known for its readability, simplicity, and versatility — making it one of the best languages for beginners.
In this post, we’ll cover key Python fundamentals and explain how to use comments to write clean, understandable code.
✅ What is Python?
Python is a high-level, interpreted programming language designed with simplicity and readability in mind. It is widely used in:
-
Web development
-
Data science
-
Machine learning
-
Automation ⚙️
- Game development
Python Fundamentals
Here are some basic building blocks you need to understand to write your first Python program:
1. Variables
Variables are used to store data:
1 2 3 |
name = "Alice" age = 25 height = 5.6 |
Python is dynamically typed, meaning you don’t need to declare data types explicitly.
2. Data Types
Some common data types in Python:
-
int
→ Integer (e.g.,10
) -
float
→ Decimal numbers (e.g.,3.14
) -
str
→ Strings (e.g.,"Hello"
) -
bool
→ Boolean values (True
,False
) -
list
,tuple
,dict
→ Collections
1 2 |
is_student = True grades = [90, 85, 88] |
3. Operators
Python supports basic arithmetic and logical operators:
1 2 3 4 5 6 |
# Arithmetic x = 5 + 3 # 8 y = 10 / 2 # 5.0 # Logical print(True and False) # False |
4. Conditional Statements
Used to make decisions in your program:
1 2 3 4 5 |
age = 18 if age >= 18: print("You can vote!") else: print("You are too young to vote.") |
5. Loops
Repeat blocks of code:
1 2 3 4 5 6 7 8 9 |
# for loop for i in range(3): print("Hello") # while loop count = 0 while count < 3: print(count) count += 1 |
Python Comments
Comments help explain what your code does, making it easier to read and maintain. They are ignored by Python during execution.
Single-line Comments
Use #
to add a comment on its own line or at the end of a line:
1 2 |
# This is a single-line comment x = 5 # This assigns 5 to x |
Multi-line Comments
Python doesn’t have a formal multi-line comment syntax, but you can simulate one using triple quotes '''
or """
:
1 2 3 4 |
''' This is a multi-line comment. It can span several lines. ''' |
Note: Technically, triple quotes create a multi-line string, not a true comment — but they’re commonly used this way in documentation or temporary blocks.
Why Use Comments?
-
Clarify why something is done (not just what)
-
Make your code easier to understand for others (and your future self!)
-
Help with debugging by commenting out parts of code temporarily
When writing Python programs, we often need to make decisions, check conditions, or control the flow of execution. At the heart of all these operations lies a simple yet powerful data type: the Boolean.
In this blog post, we’ll demystify Python Booleans and explore how they work, where they’re used, and how to master them in your day-to-day coding.
What is a Boolean in Python?
A Boolean represents one of two possible values:
-
True
-
False
In Python, Booleans are a built-in data type. They are commonly used for:
-
Decision-making (
if
statements) -
Loop control (
while
,for
) -
Comparing values
You can create Boolean values like this:
1 2 3 4 |
x = True y = False print(type(x)) # <class 'bool'> |
Boolean Values from Expressions
Booleans often come from comparisons:
1 2 3 |
print(5 > 3) # True print(2 == 5) # False print("a" != "b") # True |
Here are common comparison operators that return Boolean results:
Operator | Meaning | Example | Result | |
---|---|---|---|---|
-------- | ---------------- | -------- | ------- | |
`==` | Equal to | `5 == 5` | `True` | |
`!=` | Not equal to | `3 != 4` | `True` | |
`>` | Greater than | `7 > 2` | `True` | |
`<` | Less than | `1 < 0` | `False` | |
`>=` | Greater or equal | `4 >= 4` | `True` | |
`<=` | Less or equal | `6 <= 5` | `False` |
Boolean in if
Statements
Boolean values are most powerful when used to control logic:
1 2 3 4 5 6 |
is_raining = True if is_raining: print("Take an umbrella!") else: print("Enjoy the sunshine!") |
Since is_raining
is True
, Python executes the first block.
Booleans in Loops
You can also use Booleans in loops:
1 2 3 4 |
count = 0 while count < 3: print("Counting:", count) count += 1 |
The condition count < 3
returns a Boolean value. The loop runs while it is True
.
⚙️ The bool()
Function
Any Python value can be tested as True
or False
using the bool()
function:
1 2 3 4 5 |
print(bool(0)) # False print(bool(1)) # True print(bool("")) # False print(bool("hello")) # True print(bool([])) # False |
Truthy and Falsy Values in Python:
-
Falsy values:
-
False
-
None
-
0
,0.0
-
""
(empty string) -
[]
,{}
,()
(empty collections)
-
-
Everything else is Truthy.
Combining Booleans with and
, or
, not
Python provides logical operators to combine Boolean values:
1 2 3 4 5 6 7 8 |
# and: True if both are True print(True and False) # False # or: True if at least one is True print(True or False) # True # not: Inverts the Boolean print(not True) # False |
Real Example: Login System
1 2 3 4 5 6 7 |
username = "admin" password = "1234" if username == "admin" and password == "1234": print("Login successful!") else: print("Invalid credentials.") |
This uses Boolean logic to check two conditions at once.
Concept | Summary |
---|---|
Boolean Values | True, False |
Comparisons | Return Booleans (==, >, <, etc.) |
bool() | Converts a value to a Boolean |
Logic Operators | and, or, not |
Truthy/Falsy | Used in conditionals and loops |
Final Thoughts
Booleans are the backbone of decision-making in Python. Whether you’re checking user input, building a game, or processing data — understanding how to use True
and False
is essential for writing clean, effective code.
Master Booleans, and you master control over your programs.
Happy coding!
Python Programming
Python Programming
What is the correct file extension for Python files?
How do you insert comments in Python code?
What data type is the result of: 5 / 2 in Python 3?
Which of these is a correct variable name in Python?
Better luck next time!
Congratulations!
Introduction to Python quiz

Certificate
Promo code
Sale
5
Valid until:
May 31, 2025
You can send it to your friend. The discount can be used only once in the specified period of time.
We can send you this coupon by email