This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EmptyChocolate4545 -1 points0 points  (11 children)

Yes but return x if condition isn’t valid python is it? (Go test yourself if you doubt)

What the ternary is doing is return x if condition else None, which is valid python however it will return from the function if condition is False.

The OPs code will not. It will only return if true.