에듀테크 프로젝트 대시보드
조건문 (if · match)
블록은 들여쓰기로 구분합니다(보통 스페이스 4칸). 소괄호·중괄호는 필요 없습니다.
score = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
# 참/거짓 판정은 truthy 규칙
if items: # len(items) > 0 대신
...
if name is None: # None 비교는 is
...status = "성인" if age >= 19 else "미성년"
# 중첩 (과하면 가독성 저하)
sign = "+" if n > 0 else "-" if n < 0 else "0"
# 리스트 컴프리헨션과 결합
[x if x > 0 else 0 for x in nums]if 0 <= x < 100 and y != 0:
...
if user.is_admin or user.id == owner_id:
...
if not (a and b):
...
# in 으로 여러 값 비교
if cmd in ("q", "quit", "exit"):
...def handle(command):
match command.split():
case ["go", direction]:
return f"{direction}로 이동"
case ["drop", *items]:
return f"버림: {items}"
case ["quit" | "exit"]: # OR 패턴
return "종료"
case _: # 기본값 (와일드카드)
return "알 수 없음"match point:
case (0, 0):
print("원점")
case (x, 0):
print(f"x축 위 {x}")
case (x, y) if x == y: # 가드 조건
print("대각선")
case {"type": "circle", "r": radius}: # dict 패턴
print(f"반지름 {radius}")
case Point(x=px, y=py): # 클래스 패턴
print(px, py)case "foo": 는 리터럴 매칭이지만 case x: 는 무조건 캡처(바인딩)case Color.RED: 처럼 점(.) 포함 이름이어야 함if/elif 가 더 명확TabError / 미묘한 버그. PEP8 은 스페이스 4칸pass 를 넣어 자리 표시