🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ ADD and UPDATE Values from a List in Python (Append, Extend, Insert)
○ Add items into a List in Python
Adding items into a List in Python or updating items from a List in Python is very easy. Lists are mutable, which means their elements can be changed. In fact, you can add one item into a list using the method append(), or add several items at once using method extend().
To add new values into a list in Python, use the method append(). This method adds items only to the end of the list.
my_list = ['red', 'green', 'blue']
my_list.append('yellow')
# my_list = ['red', 'green', 'blue', 'yellow']
Furthermore, you can insert one item at a desired location, by using the method insert() in Python. If you want to insert an item at a specific position in a list, you will use the insert() method. Note that: All of the values in the list after the inserted value will be moved down one index.
my_list = ['red', 'green', 'blue']
my_list.insert(1, 'yellow')
# my_list = ['red', 'yellow', 'green', 'blue']
○ Update items from a List in Python
Updating an entry to an existing list is simply a matter of assigning a new value, with the assignment operator (=). Thus, you can replace an existing element with its new value, by assigning the new value to the desired index. Note that: List indexing in Python is zero-based, as it is with strings.
my_list = ['red', 'green', 'blue']
my_list[0] = 'yellow'
# my_list = ['yellow', 'green', 'blue']
my_list[-1] = 'orange'
# my_list = ['yellow', 'green', 'orange']
Let’s play this video, stick around and watch until the end of this video! 👍🏻
– Digital Academy™ 🎓
***
☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho
☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw
📖 Blog: http://digital.academy.free.fr/blog/
📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners
🛒 Shopping and Discounts: http://digital.academy.free.fr/store/
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧ https://twitter.com/DigitalAcademyy
✧ https://www.facebook.com/digitalacademyfr
✧ https://www.instagram.com/digital_academy_fr/
✧ https://www.youtube.com/c/DigitalAcademyOnline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ https://www.patreon.com/digital_academy
✧ https://www.buymeacoffee.com/digital_academy
***