if <variable>:(为什么没有赋值?)

If <variable>: (Why is there no value assigned?)

谁能告诉我为什么在 if begin: 的条件之后没有给 begin 赋值而只是以冒号结尾?我可以知道这是什么意思吗?

if begin:
    begin = int(begin)
    end = int(raw_input("End:"))
    print "word[", begin,":",end,"] ",
    print word[begin:end]

raw_input("\n\nPress the Enter Key to exit.") 

谢谢!

我试过下面的片段,它起作用了。

代码:

word = "PythonWizard"
print word
begin = int(raw_input("Begin:"))
if begin:
    begin = int(begin)
    end = int(raw_input("End:"))
    print "word[", begin,":",end,"] ",
    print word[begin:end]

raw_input("\n\nPress the Enter Key to exit.") 

输出: