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 Collections (Retired) Slices Slice Functions

'tuple' object has no attribute 'pop'

first_4.py

def first_4(*p):
  i = 0
  v = []
  g = p.pop(0)
  if g == len(4):
    print(g)
  else:
    False
  #if i <5:
  #  for i in len(range(p)):
  #    v.append(p[i])
  #else:
  #  print(v)

first_4("hi", "there", "man", "tier", "cart")  
Error  'tuple' object has no attribute 'pop'

its kinda crazy because p.pop() should pop the tuple item off the list.. but it still doesnn't work. Maybe you can give me a hint into a new direction, i've worked on this for a couple days..

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

.pop() takes an item off the iterable, which changes the iterable in place. Can tuples be changed or are they immutable?