Add a String to a List in Python

  • Post category:List

Adding a string to a list is a common operation in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to append or insert a string into a list efficiently.

Example 1:

fruits = ['apple', 'banana', 'kiwi']

Output: [‘apple’, ‘banana’, ‘kiwi’, ‘orange’]

Example 2:

numbers = [1, 2, 3, 5]
numbers.insert(3, 'four')

Output: [1, 2, 3, ‘four’, 5]