Jump to content

Undefined values: Difference between revisions

added python
(added php)
(added python)
Line 81:
echo "Done\n";
?></lang>
 
Results in:
 
<pre>var is undefined at first check
var is undefined at third check
Done
</pre>
 
=={{header|Python}}==
 
<lang python>
# Check to see whether it is defined
try: var
except NameError: print "var is undefined at first check"
 
# Give it a value
var = "Chocolate"
 
# Check to see whether it is defined after we gave it the
# value "Chocolate"
try: var
except NameError: print "var is undefined at second check"
 
# Give the variable an undefined value.
del var
 
# Check to see whether it is defined after we've explicitly
# given it an undefined value.
try: var
except NameError: print "var is undefined at third check"
 
# Give the variable a value of 42
var = 42
 
# Check to see whether the it is defined after we've given it
# the value 42.
try: var
except NameError: print "var is undefined at fourth check"
 
# Because most of the output is conditional, this serves as
# a clear indicator that the program has run to completion.
print "Done"
</lang>
 
Results in:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.