python中的自引用类? [英] Self-referencing classes in python?

查看:54
本文介绍了python中的自引用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中,您是否可以使用成员本身是指向同一类类型的成员的指针的类?例如,在C语言中,二进制树中的节点可能具有以下类:

In Python, can you have classes with members that are themselves pointers to members of the type of the same class? For example, in C, you might have the following class for a node in a binary tree:

struct node {
    int data;
    struct node* left;
    struct node* right;
} 

如何等效地在python中创建它?

How would you equivalently create this in python?

推荐答案

Python是一种动态语言。属性可以(几乎)在任何时间绑定任何类型。因此,您描述的问题在Python中不存在。

Python is a dynamic language. Attributes can be bound at (almost) any time with any type. Therefore, the problem you are describing does not exist in Python.

这篇关于python中的自引用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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