--- id: python-elif title: "Python Elif" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Python Elif Statement", "파이썬 elif"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["python", "programming", "w3schools", "elif", "conditions"] raw_sources: ["https://www.w3schools.com/python/python_if_elif.asp"] applied_in: [] github_commit: "" --- # [[Python Elif]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `elif` checks conditions top-to-bottom and stops at the FIRST true one β€” so even if multiple conditions would be true, only the first matching block executes, making elif chains cheaper than separate independent if statements. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`elif`** β€” "if the previous conditions were not true, then try this condition". [S1] - **Multiple elif** β€” as many as needed; Python checks each in order. [S1] - **First-match-wins** β€” execution stops at the first true condition, even if later ones would also be true. [S1] - **When to use** β€” for multiple mutually exclusive conditions; more efficient than separate if statements since checking stops early. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Mutual-exclusivity assumption** β€” elif chains are designed for conditions that are logically exclusive (e.g. grade bands); using elif for conditions that could overlap silently discards all but the first match. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Basic elif: `if b > a: ... elif a == b: print("a and b are equal")`. [S1] - Grade band chain: `if score >= 90: "A" elif score >= 80: "B" elif score >= 70: "C" elif score >= 60: "D"` β€” score 75 prints "C" only. [S1] - Day-of-week chain: 7 elif branches, one per day number. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” λ“±κΈ‰ λΆ„λ₯˜, μš”μΌ νŒλ³„μ²˜λŸΌ μƒν˜Έ 배타적인 닀쀑 쑰건 둜직의 ν‘œμ€€ νŒ¨ν„΄μ΄λ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) First-match-wins elif chain (Python): ```python score = 75 if score >= 90: print("Grade: A") elif score >= 80: print("Grade: B") elif score >= 70: print("Grade: C") # this one executes elif score >= 60: print("Grade: D") ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[Python Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[Python If Statement]], [[Python Else]], [[Python Match]] - **μ°Έμ‘° λ§₯락:** μƒν˜Έ 배타적 닀쀑 쑰건 λΆ„κΈ° β€” Match λ¬Έ(3.10+)의 λŒ€μ•ˆμœΌλ‘œλ„ λΉ„κ΅λœλ‹€. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” Python Elif Statement β€” https://www.w3schools.com/python/python_if_elif.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Python Elif Statement" page (Astra wiki-curation, P-Reinforce v3.1 format).