4. Python Operators: Arithmetic, Relational, Logical & Assignment
Operators are special symbols in Python that execute arithmetic calculations, comparisons, and logical evaluations on operands (variables and values). In pharmaceutical computing, arithmetic operators compute dilution factors and body surface areas; relational operators compare lab test values against pharmacopoeial monographs; logical operators combine multiple release criteria (e.g., hardness AND dissolution); and assignment operators update running batch totals.
Demonstrating arithmetic, relational, and logical operators in evaluating finished tablet batches.
# Batch quality parameters
tablet_hardness_kg = 5.8
disintegration_time_min = 11.5
friability_percent = 0.65
# Relational & Logical Operators for IP Tablet Release
# Standards: Hardness >= 4.5 kg, DT <= 15 min, Friability <= 1.0%
hardness_ok = tablet_hardness_kg >= 4.5
dt_ok = disintegration_time_min <= 15.0
friability_ok = friability_percent <= 1.0
# Logical AND operation: All 3 criteria must be True
batch_passed = hardness_ok and dt_ok and friability_ok
print(f"Hardness Test: {hardness_ok} | DT Test: {dt_ok} | Friability Test: {friability_ok}")
print(f"Final Batch Commercial Release: {batch_passed}")- Arithmetic Operators: `+` (add), `-` (subtract), `*` (multiply), `/` (float divide), `//` (floor/integer divide), `%` (modulus/remainder), `**` (exponentiation/power).
- Relational Operators: `==` (equal), `!=` (not equal), `>`, `<`, `>=`, `<=` (return boolean True/False).
- Logical Operators: `and` (True if both are true), `or` (True if at least one is true), `not` (inverts boolean value).
- Compound Assignment: `+=`, `-=`, `*=`, `/=` modify variables in place efficiently.
ऑपरेटर्स के ज़रिए जोड़-घटाव (Arithmetic), दो मानों की तुलना (Relational जैसे >=, <=), और कई शर्तों को एक साथ जोड़ना (Logical जैसे and, or) संभव होता है।