Python - inline if statement for print


Python tip:

You can write an if-else inside the print function (It must include else):

def is_adult(age):
    print("Adult" if age > 18 else "Child")

is_adult(17)
# -> Child

is_adult(32)
# -> Adult

age = 10
print("Adult" if age > 18)
# -> SyntaxError: expected 'else' after 'if' expression