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

pop() with index

when you used pop with index at 01:32, you didn't used the [], can we do it in python calling index in parentheses? hope you understand

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

The method pop operates like a function, in that, it's arguments are wrapped in parens ().

items = ["a", 3, "b", 9]

# remove first item using del
del items[0]  # removes the "a", 

# remove first item using pop
item_removed = items.pop(0) # removes the 3

# item_removed now holds 3

Thanks

Can you pls explain me what is happening here:

sum  = 0
i = 0
for i in range(10):
    sum = sum + i
    print(sum)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points
# set sum to zero 
sum  = 0
# set i to zero
i = 0
# loop over the numbers 0, 1,... , 9
for i in range(10):
    # add the number to sum
    sum = sum + i
    # print partial sum
    print(sum)

# produces
0
1
3
6
10
15
21
28
36
45