Theme
Primary Color

إستخدام ال Ternary Operator في ال Python

ال Ternary Operator يخليك تستخدم الشرط بشكل مبسط ومختصر

الشرط مكتوب بالطريقة العادية

age = 40
if age > 20:
  print("Suitable")
else:
  print("Not Suitable")

الشرط بال Ternary Operator

age = 40
print("Suitable") if age > 20 else print("Not Suitable")

شرح ال Syntax كالتالي

age = 40
# [Result If Condition Is True] If [Condition] Else [Result If Condition Is False]