Notifications
Clear all
0
27/03/2024 4:23 pm
Topic starter
I'm new to Python and I'm trying to create a list of values. I've seen examples using square brackets, but I'm not sure how to add or remove items from the list. Can someone provide a simple example of how to create a Python list, add items to it, and remove items from it?
1 Answer
0
26/08/2024 9:21 pm
Creating a list in Python is quite straightforward. You use square brackets to start with, like so: my_list = []
. This creates an empty list. To add items, you can use the append()
method. For example, my_list.append('apple')
will add 'apple' to your list. To remove an item, you can use the remove()
method if you know the item's value, like my_list.remove('apple')
, or pop()
if you know the index, like my_list.pop(0)
for the first item. Hope this gets you started!