PHP » PYTHON |
login |
register |
about
|
def empty( variable ): if not variable: return True return False And if you want to test empty for dictionary with key e.g. dict then- def testEmpty(dictionry,key): if key in dictionry: if dictionry[key]: return False return True Example: >>> empty( 2 ) False >>> empty( 0 ) True >>> empty( [] ) True >>> empty( True ) False >>> stud={'name':'ganesh','city':'Pune'} >>> empty(stud,'name') False >>> stud={'name':'ganesh','city':'Pune'} >>> empty(stud,'Class') True empty(PHP 4, PHP 5) empty — Determine whether a variable is empty Parameters
Return ValuesReturns FALSE if var has a non-empty and non-zero value. The following things are considered to be empty:
Changelog
Examples
Example #1 A simple empty() / isset() comparison.
<?php
Notes
See Also
|
more
Recently updated
more
Most requested
|