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 trialRitul Sharma
2,657 PointsUsing .extend(), .append(), or +, add two new items onto the end of best. Again, the items can be anything you want.
i am using best.append(4,5) but it says it looks like task 1 is no
best=[1,2,3]
best.append[5,4]
6 Answers
Umesh Ravji
42,386 PointsHi there Ritul, you aren't using the append method correctly, hence your error :)
In order to add two new items you are going to have to call the append method twice:
best=[1,2,3]
best.append(5)
best.append(4)
Make sure you understand the difference between that, and the following, as it doesn't result in the best
list containing 5 different numbers, but actually it contains [1, 2, 3, [5, 4]]
best=[1,2,3]
best.append([5, 4])
Milan Liyanage
Python Web Development Techdegree Student 2,921 PointsHi guys, the question is "Using .extend(), .append(), or +, add two new items onto the end of best. Again, the items can be anything you want. "
So first of all we have to create that list with three items in it (task 1), and use extend first and you can choose a one between append() or +.
Here's my answer and it worked for the task number 2
best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")
Obest Chatambarara
9,676 Points@Milan. I'm sure you also failed to understand the question my fellow coder. The correct answer should be as follows: best = ["hello","obest","duncan"] best.extend(["esther","sister"]) I am very new to coding but here we only need to add TWO items to the best list. This will actually make best have a total of 4 items not 5. Hence u can also choose either the .append(["esther","duncan"]) or do the same with +.
Milan Liyanage
Python Web Development Techdegree Student 2,921 PointsTask 1
best = [12, 12, 1998]
Task 2
best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")
Task 3
best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")
best.insert(0, "start")
harvey Spectre
Courses Plus Student 1,423 Pointsbest = ['red','white','blue'] best=best+['abc','def']
Obest Chatambarara
9,676 Points@Milan. if there was an AND between .extend()....and .append then in english your arguement was going to stand
Nina Maxberry
10,630 PointsUse extend to add to the list. best = ["song", "now", "fabulous"] my_best = ["love", "great"] best.extend(my_best)
A X
12,842 PointsA X
12,842 PointsWhy can't you append 2 list items at once to the list? Like why couldn't I do:
best.append(5,4)
Umesh Ravji
42,386 PointsUmesh Ravji
42,386 PointsSince I just happen to be using PyCham for an assignment anyways..
The
append()
method only takes one argument.Shmuel Zilberman
1,409 PointsShmuel Zilberman
1,409 Pointsbest=[1,2,3] best.append(5) best.append(4)
why do i need to do this twice why can't it just be on one line ?