Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Lists

help with this please

when i type my list like this for example

list=(1, 2, 3, 4) return
(1, 2, 3, 4)
list + [5, 6]

it says error someone help me please

[MOD: added formatting -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Be careful not to use built-in keywords as variable names. list is a keyword. By using it as a variable name it can not be used to create a new list using the constructor list().

>>> list
<class 'list'>
>>> list = (1, 2, 3, 4)
>>> list
(1, 2, 3, 4)
>>> type(list)
<class 'tuple'>

By using parens instead of square brackets or braces [ ], you've created a tuple. A tuple can not be changed, that is, it's immutable.

Using list + [5, 6] you are attempting to concatenate a tuple with a true list. This is not possible.

>>> list + [5, 6]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate tuple (not "list") to tuple

Perhaps, try:

items= list((1, 2, 3, 4))
# or
items = [1, 2, 3, 4]
# then use
items + [5, 6]

Post back if you need more help. Good luck !!

Haydar Al-Rikabi
Haydar Al-Rikabi
5,971 Points

Chris Freeman I tried your suggestion to create a list as such:

items= list(1, 2, 3, 4)

but it is returning the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list() takes at most 1 argument (4 given)

Aren't we supposed to pass an iterable to list(), for example a tuple:

items =  list((1, 2, 3, 4))