Is it possible to write single line return statement with if statement?

Solution 1:

Yes, it's called a conditional expression:

return None if x is None else something_else

You need an else something in a conditional for it to work.

Solution 2:

It is possible to write a standard "if" statement on a single line:

if x is None: return None

However the pep 8 style guide recommends against doing this:

Compound statements (multiple statements on the same line) are generally discouraged