Python类型 [英] Python types
本文介绍了Python类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我已经阅读了几篇文章,其中说Python的类型很弱。
我有点惊讶。所有物品似乎都有一个完美的定义
类型
我错了吗?
问候
Hello,
I''ve read several articles where it''s said that Python is weakly typed.
I''m a little surprised. All objects seem to have a perfectly defined
type
Am i wrong?
Regards
推荐答案
我认为这意味着名字,而不是对象,是弱类型的。所以你可以
有:
a = 4
a =''你好''
和没有问题。 a这个名字并没有与它相关的任何类型
。这与像C这样的强类型语言形成鲜明对比,如果你试图分配一个值,那么你需要在b / b
编译时声明名称(变量)和编译器对象的类型。另一种类型。
I think it means that names, not objects, are weakly typed. So you can
have:
a = 4
a = ''hello''
and there is no problem. The name ''a'' doesn''t have any type associated
with it. This contrasts with strongly typed language like C where you
declare the type of the name (variable) and the compiler objects at
compile time if you attempt to assign a value of a different type.
Steve M schrieb:
Steve M schrieb:
我认为这意味着名字而不是对象是弱类型的。所以你可以:
a = 4
a =''你好''
并且没有问题。 a这个名字并没有与之相关的任何类型。这与C之类的强类型语言形成对比,如果您尝试分配不同类型的值,则在编译时声明名称(变量)的类型和编译器对象。
I think it means that names, not objects, are weakly typed. So you can
have:
a = 4
a = ''hello''
and there is no problem. The name ''a'' doesn''t have any type associated
with it. This contrasts with strongly typed language like C where you
declare the type of the name (variable) and the compiler objects at
compile time if you attempt to assign a value of a different type.
void foo(){
int * c =" hello weakly typed C!" ;;
}
192:/ tmp deets
void foo() {
int *c = "hello weakly typed C!";
}
192:/tmp deets
gcc -c test.c
test.c:在函数`foo'':
test.c:5:警告:从不兼容的指针类型初始化
所以我不会叫C强类型....
区别通常在两个轴上进行:强弱和
静态动态。 Python是一种强类型的动态语言。 JAVA是
强类型静态。 PHP是弱类型的动态。
问候,
Diez
gcc -c test.c
test.c: In function `foo'':
test.c:5: warning: initialization from incompatible pointer type
So I wouldn''t call C strongly typed....
The distinction is usually made on two axis: strong-weak and
static-dynamic. Python is a strong-typed, dynamic language. JAVA is
strong-typed static. And PHP is weakly-typed dynamic.
Regards,
Diez
这篇关于Python类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文