我可以在python中实现虚函数吗? [英] can i implement virtual functions in python ?

查看:574
本文介绍了我可以在python中实现虚函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是python的新手,请原谅我,如果我问一些愚蠢的东西。

python是否提供了一种机制实现虚拟功能?

你能不能给一个代码片段...... :)

提前付款

-Prabu。

Hi,

I''m new to python, so excuse me if i''m asking something dumb.
Does python provide a mechanism to implement virtual functions?
Can you please give a code snippet also...:)
Thanx in advance
-Prabu.

推荐答案

我的朋友python编码器,告诉我所有函数在python中都是虚拟的,所以...


" ; Prabu" < PR **** @ hotmail.com> écritdansle message news:
e7 ************************** @ posting.google.com ...
my friend python coder, tell me all function are virtual in python , so...

"Prabu" <pr****@hotmail.com> a écrit dans le message news:
e7**************************@posting.google.com...


我是python的新手,请原谅我,如果我问一些愚蠢的东西。
python是否提供了实现虚函数的机制?
可以你也请给一个代码片段...... :)
Thanx提前
-Prabu。
Hi,

I''m new to python, so excuse me if i''m asking something dumb.
Does python provide a mechanism to implement virtual functions?
Can you please give a code snippet also...:)
Thanx in advance
-Prabu.



Prabu写道:


我是python的新手,请原谅我,如果我问一些愚蠢的东西。
python是否提供了实现虚函数的机制? [...]
Hi,

I''m new to python, so excuse me if i''m asking something dumb.
Does python provide a mechanism to implement virtual functions? [...]




你对虚拟功能是什么意思?


如果你的意思是虚拟方法在C ++意义上,所有方法都是Python中的虚拟




- Gerhard



What do you mean with "virtual function"?

If you mean virtual methods in the C++ sense, all methods are "virtual"
in Python.

-- Gerhard


Prabu< pr **** @ hotmail.com>写道:

....
Prabu <pr****@hotmail.com> wrote:
....
我是python的新手,请原谅我,如果我问一些愚蠢的东西。
python是否提供了实现虚函数的机制?
I''m new to python, so excuse me if i''m asking something dumb.
Does python provide a mechanism to implement virtual functions?




其他人给出了很好的回应,但无论如何我都会跳进去。


虚拟函数(使用C ++术语)仅限于

静态类型语言。根据对象的运行时类型动态解析虚函数调用

。非虚拟的

调用将在编译时根据对象的声明类型

来解析。由于Python是动态类型的,因此所有方法都是虚拟的唯一可能性是




Others have given good responses, but I''ll jump in anyway.

Virtual functions (using C++ terminology) are something limited to
statically-typed languages. A virtual function call will be resolved
dynamically, based on the runtime type of the object. A non-virtual
call will be resolved at compile-time, based on the declared type of
the object. Since Python is dynamically typed, the only possibility
is for all methods to be "virtual".


这篇关于我可以在python中实现虚函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆