Is it possible only to declare a variable without assigning any value in Python?

后端 未结 14 1849
暖寄归人
暖寄归人 2020-11-30 17:26

Is it possible to declare a variable in Python, like so?:

var

so that it initialized to None? It seems like Python allows this, but as soon

相关标签:
14条回答
  • 2020-11-30 17:58
    var_str = str()
    var_int = int()
    
    0 讨论(0)
  • 2020-11-30 17:59

    If I'm understanding your example right, you don't need to refer to 'value' in the if statement anyway. You're breaking out of the loop as soon as it could be set to anything.

    value = None
    for index in sequence:
       doSomethingHere
       if conditionMet:
           value = index
           break 
    
    0 讨论(0)
提交回复
热议问题