--- id: python-operators-logical title: "Python Operators Logical" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Logical Operators", "파이썬 논리 연산자"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: ["merged duplicate chapter python_if_logical.asp (same topic, richer examples) on 2026-07-04"] tags: ["python", "programming", "w3schools", "operators", "logical"] raw_sources: ["https://www.w3schools.com/python/python_operators_logical.asp", "https://www.w3schools.com/python/python_if_logical.asp"] applied_in: [] github_commit: "" --- # [[Python Operators Logical]] ## 🎯 한 줄 통찰 (One-line insight) `and`/`or`/`not` combine or invert conditional statements — `and` requires both true, `or` requires at least one true, `not` inverts the result — and Python evaluates `not` before `and` before `or` when they're combined. [S1][S2] ## 🧠 핵심 개념 (Core concepts) - **`and`** — True if both statements are true. [S1] - **`or`** — True if at least one statement is true. [S1] - **`not`** — reverses the result (True→False, False→True). [S1] - **Evaluation order** — `not` evaluates before `and`, which evaluates before `or`. [S2] - **Parentheses for clarity** — recommended when combining multiple logical operators, both to control evaluation order and to make intent readable. [S2] ## 🧩 추출된 패턴 (Extracted patterns) - **Truth-table thinking** — `and` is true only for (True,True); `or` is false only for (False,False) — memorizing these two edge cases covers every case. [S2] - **Guard-clause style combination** — real-world conditions often combine range checks, negation, and a "membership"-style boolean in one expression (e.g. `(age < 18 or age > 65) and not is_student or has_discount_code`), so parenthesizing sub-groups is what keeps such an expression debuggable. [S2] ## 📖 세부 내용 (Details) - AND: `x = 5; print(x > 0 and x < 10)`. [S1] - OR: `x = 5; print(x < 5 or x > 10)`. [S1] - NOT: `x = 5; print(not(x > 3 and x < 10))`. [S1] - Truth table (AND): (True,True)→True; any False present→False. [S2] - Truth table (OR): (False,False)→False; any True present→True. [S2] - Parenthesized complex condition: `if (temperature > 20 and not is_raining) or is_weekend: print("Great day for outdoor activities!")`. [S2] - Multi-variable auth check: `if username and password and is_verified: print("Login successful")`. [S2] - Range check via and: `if score >= 0 and score <= 100: print("Valid score")`. [S2] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) 소스에서 모순되는 정보는 발견되지 않음. 동일 주제가 W3Schools 사이트 내에서 "Operators" 섹션과 "Conditions" 섹션 양쪽에 거의 동일한 제목으로 중복 게재되어 있어, 이 문서에서 두 페이지 내용을 병합함. [S1][S2] ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — if 조건문/Comparison Operators 챕터와 결합되어 복합 조건을 표현할 때 쓰인다. [S1][S2] ## 💻 코드 패턴 (Code patterns) Parenthesized complex condition (Python): ```python age = 25 is_student = False has_discount_code = True if (age < 18 or age > 65) and not is_student or has_discount_code: print("Discount applies!") ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 사이트 내 중복 챕터(python_if_logical.asp)를 발견해 이 문서로 병합함 (New discovery, then merged) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[Python Tutorial]] - **관련 개념:** [[Python Operators Comparison]], [[Python If Statement]], [[Python Booleans]], [[Python Nested If]] - **참조 맥락:** 복합 조건 표현의 기본 — if/while 조건문에서 상시 사용. ## 📚 출처 (Sources) - [S1] W3Schools — Python Logical Operators (Operators 섹션) — https://www.w3schools.com/python/python_operators_logical.asp - [S2] W3Schools — Python Logical Operators (Conditions 섹션, 확장판) — https://www.w3schools.com/python/python_if_logical.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Python Logical Operators" page (Astra wiki-curation, P-Reinforce v3.1 format). - 2026-07-04: Merged content from the duplicate "Conditions" section chapter (python_if_logical.asp) — added truth tables, parenthesization guidance, and additional examples.