Python Forum

Full Version: List operation error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,
I recently registered in order to ask for help. Being a total newbie, I decided to practice with list operations, and I wanted to create a very simple program, simply using "append" and "pop".
random_list=[1, 2, 4, 8]
print(random_list.append("num"))
print(random_list.pop(1))
The bad news is, though, I'm not getting the output i wanted: while it should be [1, 2, 4, 8, "num"] and [1, 4, 8], what I get is:
None ; 2

What am I doing wrong?
Thanks in advance for your generous help, dear coders!
Hello and welcome to Python and the forums!
I wouldn't say you are doing anything wrong :)
You are not printing lists, but results (or rather return values) of the methods (functions belonging to list objects).
append method returns None, and pop method returns the popped item from the list (usually main purpose of using pop in the first place).
random_list=[1, 2, 4, 8]
random_list.append("num")
print(random_list)
random_list.pop(1)
print(random_list)
Thanks to you two for the quick answers (:
Buran's code is indeed working, so I think that's it!
Have a good day (: