2069/adding-elements-to-a-list-in-python
I have a list like this:
[5, 7, 12, 13, 24, 32]
I want to add two more elements to the list. I tried append() but that gave me a syntax error. How do I do this?
Use extend() instead:
l = [5, 7, 12, 13, 24, 32] l.append([1,2]) print(l)
This should give you
[5, 7, 12, 13, 24, 32, 1, 2]
To initialize an empty list do this: new_list ...READ MORE
ou are using Python 2.x syntax with ...READ MORE
You can use the reversed function in ...READ MORE
Not sure what your desired output is, ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
can you give an example using a ...READ MORE
You can simply the built-in function in ...READ MORE
Here's a generator that yields the chunks ...READ MORE
To count the number of appearances: from collections ...READ MORE
OR
Already have an account? Sign in.