Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Indent Multiple If-Else Statements ใน Python

การใช้ Indented Blocks เป็นคุณสมบัติสำคัญของ Python Indent Level ของ Block จะมากกว่า Statements ก่อนหน้า ดังนั้น หากมี If Statements หลายตัวในโปรแกรมแบบ Nested แต่ละ Indented Block ต่อไปจะมีระดับ Indent ที่เพิ่มขึ้น

if expr1 == True:
    if expr2 == True:
        stmt1
    else:
        if expr3 == True:
            stmt2
else:
    if expr3 == True:
        stmt3
    else:
        stmt4