Log in from a computer to take this course

You'll need to log in from a computer to start Learn Complex Data Structures. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store

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.



Within script.py define an empty TreeNode class.


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


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


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

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?