Is Python strongly typed?

后端 未结 11 1366
长发绾君心
长发绾君心 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条回答
  •  无人及你
    2020-11-22 17:35

    The term "strong typing" does not have a definite definition.

    Therefore, the use of the term depends on with whom you're speaking.

    I do not consider any language, in which the type of a variable is not either explicitly declared, or statically typed to be strongly typed.

    Strong typing doesn't just preclude conversion (for example, "automatically" converting from an integer to a string). It precludes assignment (i.e., changing the type of a variable).

    If the following code compiles (interprets), the language is not strong-typed:

    Foo = 1 Foo = "1"

    In a strongly typed language, a programmer can "count on" a type.

    For example, if a programmer sees the declaration,

    UINT64 kZarkCount;

    and he or she knows that 20 lines later, kZarkCount is still a UINT64 (as long as it occurs in the same block) - without having to examine intervening code.

提交回复
热议问题