empty¶
-
privex.helpers.common.
empty
(v, zero: bool = False, itr: bool = False) → bool[source]¶ Quickly check if a variable is empty or not. By default only ‘’ and None are checked, use
itr
andzero
to test for empty iterable’s and zeroed variables.Returns
True
if a variable isNone
or''
, returnsFalse
if variable passes the testsExample usage:
>>> x, y = [], None >>> if empty(y): ... print('Var y is None or a blank string') ... >>> if empty(x, itr=True): ... print('Var x is None, blank string, or an empty dict/list/iterable')
- Parameters
v – The variable to check if it’s empty
zero – if
zero=True
, then returnTrue
if the variable is int0
or str'0'
itr – if
itr=True
, then returnTrue
if the variable is[]
,{}
, or is an iterable and has 0 length
- Return bool is_blank
True
if a variable is blank (None
,''
,0
,[]
etc.)- Return bool is_blank
False
if a variable has content (or couldn’t be checked properly)