python if not none in one line

Solutions on MaxInterview for python if not none in one line by the best coders in the world

showing results for - "python if not none in one line"
Giorgia
24 Feb 2019
1#if X is None, do nothing
2>>> x = ''
3>>> x if x and x>0 else None
4#if x is not None, print it
5>>> x = 1
6>>> x if x and x>0 else None
71
Sergio
21 Mar 2020
1v = get_value()
2x = v if v is not None