Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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]
Chris FreemanTreehouse Moderator 67,622 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 <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.
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
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-Rikabi5,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))