类foo,类foo()和类foo(object)之间的区别? [英] Difference between class foo , class foo() and class foo(object)?

查看:86
本文介绍了类foo,类foo()和类foo(object)之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到所有3-> class foo class foo() class可以使用foo(object),但是我对这3个之间的区别感到困惑,如果有的话? (我的意思主要是在属性中, python3

I noticed all 3 -> class foo, class foo() and class foo(object) can be used but i am confused as to what is the difference between these 3, if there is any? (I mean in properties mainly, python3)

推荐答案

让我们打破它们down:

Let's break them down:


  1. class foo


  • Python 3 :通常是这样。默认情况下,Python为您添加 object 作为基类。

  • Python 2 :它会创建旧样式 classobj ,这会引起您各种麻烦。 / li>
  • Python 3: It's usually the way to go. By default, Python adds object as the base class for you.
  • Python 2: It creates an old style classobj that will cause you all sorts of headaches.

class foo()


  • Python 3 Python 2 :类似于 foo类对于这两个Python版本,都将其修剪掉,看起来很难看,没有区别。

  • Python 3 and Python 2: Similar to class foo for both Python versions, trim it off, it looks ugly and makes no difference.

  • Python 3 Python 2 :在这两个Python中,都将生成具有所有最熟悉的东西的新样式类。人们在编写可能也在Python 2 中使用的代码时通常也会使用这种形式,显式地从对象继承会导致该类成为Python 2中的新样式,而在3中没有任何区别(除了一些额外的输入)。

  • Python 3 and Python 2: In both Pythons, results in a new style class that has all the goodies most know. People usually use this form when writing code that might be used in Python 2 too, explicitly inheriting from object causes the class to be new style in Python 2 and makes no difference in 3 (apart from some extra typing).

这篇关于类foo,类foo()和类foo(object)之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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