Python类型安全吗? [英] Is Python type safe?
问题描述
您好,
我想知道类型安全的定义以及Python
是否可以被视为类型安全语言。同样是Java,C#或
C ++类型安全吗?
问候,
Srijit
在文章< 22 ************************** @ posting.google.com> ;,
sr****@yahoo.com 写道:
您好,
我想知道类型安全的定义以及Python是否可以被视为一种类型安全的语言。同样是Java,C#或
C ++类型安全吗?
Srijit
你告诉我你是什么意思是类型安全,我会告诉你那些
语言是否符合这个定义。
C ++和Java都有这个概念声明变量以保存某些类型的数据。我对C#一无所知,但我会假设我将b $ b放入C ++ / Java阵营。
Python on the另一方面,携带类型信息和
数据,而不是保存数据的变量(容器)。
C ++和Python都不会让你将整数3添加到字符串
" four",但使用不同的机制来阻止它。奇怪的是,Java
(在类似perl,但无可否认,方便,刺激自动化
多态)将允许你添加它们。不知道C#做了什么。
哪种类型安全,哪个不是?好吧,我想我们已经回到了我的
第一个声明,否则我们很快就会玩三个盲人
和大象。
Roy Smith写道:
C ++和Python都不允许你将整数3添加到字符串
four中,但使用不同的防止它的机制。奇怪的是,Java(在类似Perl,但无可否认,方便,刺激自动化的多态性)将允许您添加它们。不知道C#做了什么。
自从Java编辑以来已经有一段时间了,但是它并没有附加。它们,如在
中将整数转换为字符串然后加入两个字符串,而不是bb而不是add他们(我的意思是计算总和)?
(这可能就是你的意思,但我只是在检查。我会的是
惊讶地发现Java实际上隐含地执行了字符串到值的转换
。)
-Peter
srijit>我想知道类型保险箱的定义
尝试阅读
http://en.wikipedia.org/wiki/Talk:Datatype
(通过google找到维基百科类型安全)。
srijit>以及Python是否可以被视为类型安全
srijit>语言。同样是Java,C#或C ++类型安全吗?
Python:是的。我不知道Java或C#但我的猜测是,因为C ++
有演员阵容你可以让它做一些不安全的事情。
Skip
Hello,
I would like to know the definition of type safe and whether Python
can be considered as a type safe language. Similarly are Java, C# or
C++ type safe?
Regards,
Srijit
In article <22**************************@posting.google.com >,
sr****@yahoo.com wrote:
Hello,
I would like to know the definition of type safe and whether Python
can be considered as a type safe language. Similarly are Java, C# or
C++ type safe?
Regards,
Srijit
You tell me what you mean by "type safe", and I''ll tell you if those
languages meet that definition.
C++ and Java both have the concept of declaring variables to hold a
certain type of data. I don''t know anything about C#, but I''ll assume I
can lump it into the C++/Java camp.
Python on the other hand, carries the type information along with the
data, not with the variable (container) that holds the data.
Neither C++ nor Python will let you add the integer 3 to the string
"four", but use different mechanisms to prevent it. Oddly enough, Java
(in a perl-like, but admittedly convenient, stab at automagic
polymorphism) will let you add them. No clue what C# does.
Which is type safe and which isn''t? Well, I think we''re back to my
first statement, otherwise we quickly get into playing three blind men
and the elephant.
Roy Smith wrote:
Neither C++ nor Python will let you add the integer 3 to the string
"four", but use different mechanisms to prevent it. Oddly enough, Java
(in a perl-like, but admittedly convenient, stab at automagic
polymorphism) will let you add them. No clue what C# does.
It''s been a while since I Java-ed, but doesn''t it "append" them, as in
convert the integer to a string and then join the two strings, rather
than "add" them (which I take to mean "calculate the sum of")?
(That''s probably what you meant, but I''m just checking. I''d be
surprised to find that Java actually performed the string-to-value
conversion implicitly.)
-Peter
srijit> I would like to know the definition of type safe
Try reading
http://en.wikipedia.org/wiki/Talk:Datatype
(found by googling for "wikipedia type safety").
srijit> and whether Python can be considered as a type safe
srijit> language. Similarly are Java, C# or C++ type safe?
Python: yes. I don''t know about Java or C# but my guess is that since C++
has casts you can make it do some type unsafe things.
Skip
这篇关于Python类型安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!