Is Python strongly typed?

后端 未结 11 1424
长发绾君心
长发绾君心 2020-11-22 17:12

I\'ve come across links that say Python is a strongly typed language.

However, I thought in strongly typed languages you couldn\'t do this:

bob = 1
b         


        
11条回答
  •  猫巷女王i
    2020-11-22 17:35

    A Python variable stores an untyped reference to the target object that represent the value.

    Any assignment operation means assigning the untyped reference to the assigned object -- i.e. the object is shared via the original and the new (counted) references.

    The value type is bound to the target object, not to the reference value. The (strong) type checking is done when an operation with the value is performed (run time).

    In other words, variables (technically) have no type -- it does not make sense to think in terms of a variable type if one wants to be exact. But references are automatically dereferenced and we actually think in terms of the type of the target object.

提交回复
热议问题