# A practical List.push example / understanding "null" in List usage

**URL:** https://forum.dfinity.org/t/a-practical-list-push-example-understanding-null-in-list-usage/26213
**Category:** Language Support
**Created:** [January 5, 2024, 12:26am UTC](https://forum.dfinity.org/t/a-practical-list-push-example-understanding-null-in-list-usage/26213 "2024-01-05T00:26:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nolma](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@nolma](https://forum.dfinity.org/u/nolma)
#### Post date: [January 5, 2024, 12:26am UTC](https://forum.dfinity.org/t/a-practical-list-push-example-understanding-null-in-list-usage/26213/1 "2024-01-05T00:26:01Z")

</div>

The examples from the documentations use “null” in place of lists for operations like:

```auto
List.push<Nat>(0, null) // => ?(0, null);

```

the resulting value doesn’t, at a glance, appear to be a List. This was confusing. I would like to see more practical examples for the List operations.

I’m also wondering, is “null” interpreted as an empty list?  
What does “?(0, null);” mean?

I would expect something like:

```auto
var numbers = List.nil<Nat>;
numbers := List.append<Nat>(1, numbers); //List<Nat>[1]

```

---

<div class="post-metadata">

### Author: ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)
#### Post date: [January 5, 2024, 10:40am UTC](https://forum.dfinity.org/t/a-practical-list-push-example-understanding-null-in-list-usage/26213/2 "2024-01-05T10:40:06Z")

</div>

The List type is [represented](https://github.com/dfinity/motoko-base/blob/master/src/List.mo#L22) as an optional pair of a value and a tail list:

```auto
public type List<T> = ?(T, List<T>);

```

This effectively is a single-linked list, where `null` (the empty option) represents the empty list.

```auto
let a = null; // [], same as List.nil<T>
let b = ?(1, null); // [1]
let c = ?(1, ?(2, null)); // [1, 2]
let d = ?(0, c); // [0, 1, 2], same as List.push(0, c)

```

`List.append` on the other hand concatenates two lists, so your example won’t type-check. This does:

```auto
let e = List.append(d, d); // [0, 1, 2, 0, 1, 2]

```
