nakkulable
nakkulable

Reputation: 38

Why does the following code snippet returns None?

This should append the values in the list val from the new list I am creating here using range method.

val = [1, 2, 3,'time is', 10, 'up']
print val.extend(range(0,10))

Upvotes: 0

Views: 55

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121962

list.extend() extends the list object in place and returns None.

You can print val after extending:

val.extend(range(0,10))
print val

or use concatenation:

print val + range(0, 10)

Upvotes: 5

Related Questions