-1

I'm using the code below:

a = ('Monty Python', 'British', 1969) #a is a tuple
b=list(a) #this should convert it to a list if I'm not wrong
print(b) #the output till here is okay
c=b.append("abcd") 
print(c) # the output for this is None

Can anyone explain why am I unable to edit after converting the tuple to a list??

Black Thunder
  • 6,215
  • 5
  • 27
  • 56

2 Answers2

0

.append() does not return a list.

You are doing c = b.append("abcd"), this makes no sense because b.append() does not return a list, it returns none.

Try print(type(b.append("abcd"))) and see what it prints. So as you can see python is working correctly.

Things like .append() .pop() do not return a new list, they change the list in memory.

This is called an inplace operation I believe

Alexis Drakopoulos
  • 1,102
  • 6
  • 19
0

You're printing c whose job is to append. Print b instead, that's your list.

Muhammad Hamza
  • 743
  • 15
  • 37