|
|
|
|
|
by pmart123
2065 days ago
|
|
Switch statements can work well from a readability standpoint such as the HTTP error example they use. However, I almost feel it is more Pythonic to use a dictionary instead, collapsing the function into: def http_error(status): try:
return HTTP_STATUS_CODES[status]
except KeyError:
return "Something else"
Also, method polymorphism always seemed more powerful and intuitive to me than switch statements when the operation is something like: multiply(scalar, scalar)
multiply(vector, scalar)
multiply(matrix, scalar)
|
|