How to add an Item in List in Python?
Postado 2022-10-13 09:27:46
0
46
append()
method:
append() method is used to add an item to the end of the list.
Example:
myList = ["List Item 1", "List Item 2", "List Item 3"]
myList.append("List Item 4")
print(myList)
insert()
method:
insert() method is used to insert a list item at a specified index.
myList = ["List Item 2", "List Item 3", "List Item 4"]
myList.insert(1, "List Item 1")
print(myList)
extend()
method:
extend() method is used to append elements from another list to the current list.
myList = ["List Item 2", "List Item 3", "List Item 4"]
myList2 = ["List Item 5", "List Item 6", "List Item 7"]
myList.extend(myList2)
print(myList)
Pesquisar
Categorias
- Information Technology
- Office Equipment and Supplies
- Cars and Trucks
- Persons
- Books and Authors
- Tutorials
- Art
- Causes
- Crafts
- Dance
- Drinks
- Film
- Fitness
- Food
- Jogos
- Gardening
- Health
- Início
- Literature
- Music
- Networking
- Outro
- Party
- Religion
- Shopping
- Sports
- Theater
- Wellness
Leia Mais
How Long Does Hydrocodone Stay in Your System?
Hydrocodone is in a class of medications called opiate analgesics in a class of medications...
© 2025 Omaada - A global social and professionals networking platform
Portuguese
