Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declaring empty class member in python

i am trying to read a tree structure file in python. I created a class to hold the tree objects. One of the members should hold the parent object. Since the parentObject member is of the same type as the class itself, I need to declare this as an empty variable of type "self".

How do I do that in python?

Thank you very much for your help.

like image 595
Draetsch Avatar asked Dec 17 '09 23:12

Draetsch


People also ask

How do you declare an empty class in Python?

In Python, to write an empty class pass statement is used. pass is a special statement in Python that does nothing. It only works as a dummy statement. However, objects of an empty class can also be created.

How do you declare an empty value in Python?

In order to define a null variable, you can use the None keyword. Note: The None keyword refers to a variable or object that is empty or has no value. It is Python's way of defining null values.

Can we declare an empty class?

C++ allows creating an Empty class, yes! We can declare an empty class and its object. The declaration of Empty class and its object are same as normal class and object declaration.

How do you empty an object in Python?

To delete an object in Python, we use the 'del' keyword. A when we try to refer to a deleted object, it raises NameError.


1 Answers

In Python, you don't declare variables as having any type. You just assign to them. A single variable can be assigned objects of different types in succession, if you wanted to do so. "self" is not the type but a naming convention used to refer to the current object, like "this" in Java / C++ (except in Python you could call it anything you wanted).

like image 81
danben Avatar answered Nov 07 '22 06:11

danben