0
Why I cannot use append method in python?
Why I cannot write it: cubes.append(9) print(cubes) as print(cubes.append(9)
3 ответов
+ 7
Because append method doesn't returns a new list or anything else,it modifies original list .
+ 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!
+ 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.