This is going to sound like a dumb and horrible idea and that's probably because it is.
Is there a way in Python (preferably a one-liner) to create an expression that resolves to a value if a condition is met but if the condition is not met it will instead execute a statement (such as continue
or a method call)?
An example use case below (although this code doesn't actually work):
def print_name_if_even(n):
print(f"{ name if n % 2 == 0 else print("Uneven!") }")
I know this probably is a bad idea but I'm doing a challenge to cram a function definition in as few lines as possible so I want to avoid muli-line conditional statements.