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

后端 未结 14 1868
暖寄归人
暖寄归人 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:52

    I'd heartily recommend that you read Other languages have "variables" (I added it as a related link) – in two minutes you'll know that Python has "names", not "variables".

    val = None
    # ...
    if val is None:
       val = any_object
    

提交回复
热议问题