Are there any declaration keywords in Python?

前端 未结 5 1978
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 10:48

Are there any declaration keywords in python, like local, global, private, public etc. I know it\'s type free but how do you know if this statement:

x = 5;
         


        
5条回答
  •  旧时难觅i
    2021-02-03 11:06

    It doesn't look like the asker is trying to assign a type, just to specify that this a declaration, not an assignment.

    Looks like you are looking for something like javascript has:

    var x = 5;
    

    The concept of the declaration keyword in javascript is to ensure that you are making a new object in the current scope and are not simply changing some other variable of the same name.

    Python does not have this feature. The programmer has to make sure that he or she is not reassigning preexisting names.

提交回复
热议问题