0 votes
1 view
in Python by (47.8k points)

I am a C programmer. I am new to python. In C, when we define the structure of a binary tree node we assign NULL to it's right and left the child as :

struct node 

int val; 

struct node *right ; 

struct node *left ; 


And when initializing a node, we write as :

val = some_value

right = NULL; 

left = NULL;

Now my question is: how can we assign a NULL value to right and left pointers of the node in Python?

And how can we test against the Python version of NULL? In C it would be:

if( ptr->right == NULL )

Thank you!

1 Answer

0 votes
by (107k points)

In Python we use None instead of NULL. As all objects in Python are implemented via references, See the code below:-

class Node: 

  def __init__(self): 

    self.val = 0

    self.right = None

    self.left = None 

Related questions

0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !