我在Python初學者,我寫了這個簡單的代碼,但也有一些我無法解析:(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"
你看到了什麼樣的錯誤?這裏有一些縮進錯誤會使這段代碼立即失效。如果這些是複製粘貼錯誤,您需要修復並重新發布代碼。 – larsks
//不是python中的註釋#用於註釋 –
爲什麼使用//當你可以(並且在真正的代碼中必須)使用# – loki