56 - Mastering Conditional Statements: if-else Explained

Опубликовано: 22 Июль 2026
на канале: القبعة البيضاء
149
9

   • 55 - Mastering Cisco IOS: Expert Guide to ...  
55 - Mastering Cisco IOS: Expert Guide to Configuration Submodes and Contexts.
54 - CLI Help Features & The debug and show Commands.
   • 54 - CLI Help Features & The debug and sho...  
54 - Iteration Loops (for Loops) | تعلم البرمجة وأتقنها بكل سهولة
   • 54 - Iteration Loops (for Loops) | تعلم ال...  

Often, you’ll want to take one action when a conditional test passes and
a different action in all other cases. Python’s if-else syntax makes this possible. An if-else block is similar to a simple if statement, but the
else statement allows you to define an action or set of actions that are
executed when the conditional test fails.
We’ll display the same message we had previously if the person is old
enough to vote, but this time we’ll add a message for anyone who is not
old enough to vote.

"غالبًا ما ستحتاج إلى اتخاذ إجراء معين عند اجتياز اختبار شرطي وإجراء مختلف في جميع الحالات الأخرى. يجعل بناء جملة if-else في بايثون هذا ممكنًا. يشبه بلوك if-else عبارة if بسيطة، لكن عبارة else تسمح لك بتحديد إجراء أو مجموعة من الإجراءات التي يتم تنفيذها عند فشل الاختبار الشرطي. سنعرض نفس الرسالة التي لدينا سابقًا إذا كان الشخص مؤهلاً للتصويت، ولكن هذه المرة سنضيف رسالة لأي شخص غير مؤهل للتصويت."