-2

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??

Nouman
  • 6,947
  • 7
  • 32
  • 60

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,115
  • 7
  • 22
0

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

Muhammad Hamza
  • 823
  • 1
  • 17
  • 42