转载: https://www.zhihu.com/question/19918532

 

弱类型:
> "1"+2
'12'
 
强类型:
>>> "1"+2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
 
动态类型:
>>> a = 1
>>> type(a)
<type 'int'>
>>> a = "s"
>>> type(a)
<type 'str'>
 
静态类型:
Prelude> let a = "123" :: Int

<interactive>:2:9:
    Couldn't match expected type `Int' with actual type `[Char]'
    In the expression: "123" :: Int
    In an equation for `a': a = "123" :: Int
 
编程语言的弱类型、强类型、动态类型、静态类型

 

 

相关文章:

  • 2020-04-08
  • 2021-07-26
  • 2021-10-02
  • 2021-11-24
  • 2021-10-20
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2021-06-22
  • 2021-06-01
  • 2021-01-10
  • 2021-05-18
  • 2021-10-27
  • 2021-07-30
  • 2022-02-10
相关资源
相似解决方案