如果<variable> :(为什么没有赋值?)</variable>

时间:2015-03-12 03:16:09

标签: python variables if-statement branch conditional-statements

有人可以告诉为什么在begin的条件之后没有为if 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.") 

谢谢!

1 个答案:

答案 0 :(得分:0)

我尝试了下面的剪辑并且有效。

代码:

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.") 

输出:

enter image description here

相关问题