0

Why I cannot use append method in python?

Why I cannot write it: cubes.append(9) print(cubes) as print(cubes.append(9)

15th Jan 2021, 3:52 PM
Even Dead I Am The Hero.
Even Dead I Am The Hero. - avatar
3 ответов
+ 7
Because append method doesn't returns a new list or anything else,it modifies original list .
15th Jan 2021, 3:54 PM
Abhay
Abhay - avatar
+ 7
The output will be None! Because append() function does not return anything , Correct way to do a = [] a.append(2) print(a) Output - [2] All the best!
15th Jan 2021, 4:02 PM
Abhiyantā
Abhiyantā - avatar
+ 3
Or if you want to append the element inside the "print" statement so it will print the list right away like what you are trying to do. print( list + [elements] ) print( cubes + [9] ) # You can append multiple elements. print( cubes + [9, 27, 81] ) Or you can just follow their answers if you want to use append method.
15th Jan 2021, 4:04 PM
noteve
noteve - avatar