Skip to Content
Learn
Trees: Python
Tree Implementation I: Planting Seeds

Let’s start by defining our TreeNode class. We’ll begin with having our node store a value, and additional functionality can be layered on in the following exercises.

Instructions

1.

Within script.py define an empty TreeNode class.

2.

Inside the TreeNode class, define an __init__() method that takes self and value as parameters. Print “initializing node…” within __init__().

3.

Inside __init__(), assign value to self.value.

4.

Nice work! Make an instance of TreeNode and give it the value of your name as a string. Assign this to the variable: seed.

Folder Icon

Sign up to start coding

Already have an account?