---
# System prepended metadata

title: Binary tree construction in Python

---

# Binary tree construction in Python

```python=
class TreeNode:
  def __init__(self, val=0, left=None, right=None):
    self.val = val
    self.left = left
    self.right = right

t2 = TreeNode(2)
t3 = TreeNode(3)
t1 = TreeNode(1, t2, t3)
```