Relational Operators
Nerd Cafe | نرد کافه
Step 1: What Are Relational Operators?
Relational operators (also called comparison operators) are used to compare two values. Each comparison returns a Boolean result — either:
TrueFalse
Step 2: List of Relational Operators in Python
==
Equal to
a == b
!=
Not equal to
a != b
>
Greater than
a > b
<
Less than
a < b
>=
Greater than or equal to
a >= b
<=
Less than or equal to
a <= b
Step 3: Try Simple Examples
a = 10
b = 20
print(a == b) # False
print(a != b) # True
print(a > b) # False
print(a < b) # True
print(a >= b) # False
print(a <= b) # TrueNote: Relational operations always return either True or False.
Step 4: Real-World Examples
Example 1: Age Check System
Output: You're eligible to vote.
Example 2: Comparing Strings (Alphabetical Order)
Note: String comparison is based on Unicode (ASCII) values, not dictionary order.
Step 5: Applications in Machine Learning
Relational operators are widely used in ML for:
Filtering datasets
Conditional logic
Feature selection
Performance evaluation
Example 3: Thresholding Predictions
Output: Class 1
Example 4: Filtering Data with Pandas
Output:
Note: In Pandas, relational operators work element-wise.
Step 6: Combining Relational and Logical Operators
Output: Good score
This kind of condition is often used in ML for model evaluation:
Step 7: Using Relational Operators with NumPy Arrays
Use Case: Commonly used for filtering predictions, feature values, and other numeric conditions.
Summary Table (Quick Reference)
Video Tutorial
Support Our Work
If you find this post helpful and would like to support my work, you can send a donation via TRC-20 (USDT). Your contributions help us keep creating and sharing more valuable content.
TRC-20 Address: TAAVVf9ZxUpbyvTa6Gd5SGPmctBdy4PQwf
Thank you for your generosity! 🙏
Keywords
relational operators, comparison operators, python operators, boolean values, true false, equality operator, inequality operator, greater than, less than, logical conditions, conditional statements, python basics, data filtering, pandas comparison, numpy mask, machine learning conditions, thresholding, string comparison, feature selection, boolean logic, nerd cafe , نرد کافه
Channel Overview
🌐 Website: www.nerd-cafe.ir
📺 YouTube: @nerd-cafe
🎥 Aparat: nerd_cafe
📌 Pinterest: nerd_cafe
📱 Telegram: @nerd_cafe
📝 Blog: Nerd Café on Virgool
💻 GitHub: nerd-cafe
Last updated