+ 5

What is the mistake in this code?

It gives output as none... queue = ['John', 'Amy', 'Bob', 'Adam'] a=input() print(queue.append(a))

13th Oct 2022, 11:54 AM
Riya
Riya - avatar
7 Answers
+ 7
What are you trying to print? Input or queue? queue.append( a ) print( queue )
13th Oct 2022, 12:13 PM
Jayakrishna 🇼🇳
+ 7
Riya , here a short explanation why your code prints *None*. <list>.append() is adding a new element at the end of the list. this is done in place, this means no new list is created. all functions that are working in place do not give a return value. in this case *None* is printed.
13th Oct 2022, 2:25 PM
Lothar
Lothar - avatar
+ 6
Thank you I got the output
13th Oct 2022, 2:11 PM
Riya
Riya - avatar
+ 4
Thank you Lothar nice explanation 👍
13th Oct 2022, 2:28 PM
Riya
Riya - avatar
+ 2
When i tried this code, it didn't work context.rect(50,50,100,50); context.stroke();
15th Oct 2022, 10:32 AM
Abigail Quansah
Abigail Quansah - avatar
0
Well u cant access a variable that you deklarate just in the moment, like my foreposters already said: first apply the value THAN read the value.
14th Oct 2022, 7:24 PM
S3R43o3
S3R43o3 - avatar