我是 Python 的初学者,我已经编写了这个简单的代码,但是有一些我无法解决的错误:(
请问有人可以帮我吗?
//initialization
str = None
var = None
def setvar(val):
""" Sets the global variable "var" to the value in 'val' """
if val:
print "setting variable 'var' to '$val'" // we want to print the value of 'val'
else:
print "un-setting variable 'var'"
var = val
return
if __name__ == 'main':
try:
setvar(" hello world! ") // use this function to set the 'var' variable
var.strip() // we want the leading and trailing spaces removed
print str(var)
except:
print "something went wrong"