Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python if not none in one line

#if X is None, do nothing
>>> x = ''
>>> x if x and x>0 else None
#if x is not None, print it
>>> x = 1
>>> x if x and x>0 else None
1
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #line
ADD COMMENT
Topic
Name
5+4 =