静态类型/动态类型/强类型/弱类型

这里写图片描述

C/C++是弱类型,并且是静态类型,因为可以容忍隐式类型转换,并且可以进行强制类型转换,然后编译的时候就已经直到变量的类型,所以是静态类型(类型错误引发的是语法错误)

python是动态类型,强类型,偏向于不容忍隐式类型转换。

wiki上关于强类型:
Java, Pascal, Ada and C require all variables to have a declared type, and support the use of explicit casts of arithmetic values to other arithmetic types. Java, C#, Ada and Pascal are sometimes said to be more strongly typed than C, a claim that is probably based on the fact that C supports more kinds of implicit conversions, and C also allows pointer values to be explicitly cast while Java and Pascal do not. Java itself may be considered more strongly typed than Pascal as manners of evading the static type system in Java are controlled by the Java virtual machine’s type system**. C# and VB.NET are similar to Java in that respect**, though they allow disabling of dynamic type checking by explicitly putting code segments in an “unsafe context”. Pascal’s type system has been described as “too strong”, because the size of an array or string is part of its type, making some programming tasks very difficult.[7]

Smalltalk, Perl, Ruby, Python, and Self are all “strongly typed” in the sense that typing errors are prevented at runtime and they do little implicit type conversion, but these languages make no use of static type checking: the compiler does not check or enforce type constraint rules. The term duck typing is now used to describe the dynamic typing paradigm used by the languages in this group.

The Lisp family of languages are all “strongly typed” in the sense that typing errors are prevented at runtime. Some Lisp dialects like Common Lisp or Clojure do support various forms of type declarations[8] and some compilers (CMUCL[9] and related) use these declarations together with type inference to enable various optimizations and also limited forms of compile time type checks.
Standard ML, F#, OCaml, Haskell, and Rust are statically type-checked, but the compiler automatically infers a precise type for most values.

Visual Basic is a hybrid language. In addition to variables with declared types, it is also possible to declare a variable of “Variant” data type that can store data of any type. Its implicit casts are fairly liberal where, for example, one can sum string variants and pass the result into an integer variable. Visual Basic is weakly typed.

Assembly language and Forth have been said to be untyped. There is no type checking; it is up to the programmer to ensure that data given to functions is of the appropriate type. Any type conversion required is explicit.

wiki 上的 Type system

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值