Can someone tell me what Strong typing and weak typing means and which one is better?

后端 未结 8 1141
名媛妹妹
名媛妹妹 2020-12-13 03:56

Can someone tell me what Strong typing and weak typing means and which one is better?

8条回答
  •  情书的邮戳
    2020-12-13 04:44

    Strong/weak typing in a language is related to how easily you can do type conversions:

    For example in Python:

    str = 5 + 'a' 
    # would throw an error since it does not want to cast one type to the other implicitly.
    

    Where as in C language:

    int a = 5;
    a = 5 + 'c';
    /* is fine, because C treats 'c' as an integer in this case */
    

    Thus Python is more strongly typed than C (from this perspective).

提交回复
热议问题