자연스럽지 않은 None 사용

def divide(a, b):
    try:
        return a / b
    except ZeroDivisionError:
        return None
result = divide(x, y)
if result is None:
    print("Invalid inputs")
x, y = 0, 5
result = divide(x, y)
if not result:
    print("Invalid inputs")

None으로 인한 오류를 줄이는 방법

def divide(a, b):
    try:
        return True, a / b
    except ZeroDivisionError:
        return False, None

success, result = divide(x, y)
if not success:
    print("Invalid inputs")

# 잘못된 사용
_, result = divide(x, y)
if not result:
    print("Invalid inputs")
def divide(a, b):
    try:
        return a / b
    except ZeroDivisionError as e:
        raise ValueError("Invalid inputs") from e

x, y = 5, 2
try:
    result = divide(x, y)
except VallueError:
    print("Invalid inputs")
else:
    print("Result is %.1f" % result)

>>>
Result is 2.5