Значения разных типов

Поток управления / Условные операторы / Оператор match

class Tiger:
    pass


def describe(obj):
    match obj:
        case 2:
            return "two"
        # None is matched by identity
        case None:
            return "Empty value"
        case Tiger():
            return "Tiger!!!"
        case "Error":
            return "Error string"
        case int():
            return "Int type"
        case str(s):
            return f"string value '{s}'"
        case _:
            return "Unknown type"


print(f"{describe(Tiger()) = }")
print(f"{describe('test') = }")
print(f"{describe(5) = }")
print(f"{describe(2) = }")
print(f"{describe(None) = }")
print(f"{describe(3.14) = }")