Undefined values: Difference between revisions

→‎{{header|Python}}: Modified comments to stress creation/deletion. There is no 'undefined' value to give.
(→‎{{header|Python}}: Modified comments to stress creation/deletion. There is no 'undefined' value to give.)
Line 352:
 
=={{header|Python}}==
<lang python># Check to see whether ita variable is defined
try: var
except NameError: print "var is undefined at first check"
 
# GiveCreate a variable, giving it a string value
var = "Chocolate"
 
# Check to see whether itthe variable is defined after we gave it thenow.
# value "Chocolate"
try: var
except NameError: print "var is undefined at second check"
 
# GiveRemove the variabledefinition anof undefinedthe valuevariable.
del var
 
# Check to see whether it is defined after we'vethe explicitlyexplicit removal.
# given it an undefined value.
try: var
except NameError: print "var is undefined at third check"
 
# GiveRecreate the variable, giving it a value of 42
var = 42
 
# Check to see whether the itvariable is defined after we've given itnow.
# the value 42.
try: var
except NameError: print "var is undefined at fourth check"
Anonymous user