-1

I am a bit confused about how I can add a variable to a list in python. I have looked at this post

and this was not very helpful. This is the code I have:

lst = [1, 2, 3]
        something = 4
        print(lst.append(something))

This for some reason returns none. Unsure if I am missing something. Any help would be grateful.

3

2 Answers 2

-1
lst = [1, 2, 3]
something = 4
res = [int(something)]
print(lst + res)
Sign up to request clarification or add additional context in comments.

Comments

-2
lst = [1, 2, 3]
something = 4
lst.append(something)
print(lst)

2 Comments

This answer returns none.
Does it now? I ran this on a debugger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.