Python | Append String to list
Sometimes, while working with data, we can have a problem in which we need to add elements to a container. List can contain any type of data type. Let’s discuss certain ways in which we can perform string append operation in list of integers.
Method #1 : Using + operator + list conversion
In this method, we first convert the string into a list and then perform the task of append using + operator.
# Python3 code to demonstrate working of # Appending String to list # using + operator + list conversion # initialize list test_list = [1, 3, 4, 5] # initialize string test_str = 'gfg' # printing original list print("The original list : " + str(test_list)) # printing original string print("The original string : " + str(test_str)) # Appending String to list # using + operator + list conversion test_list += [test_str] # printing result print("The list after appending is : " + str(test_list)) |
The original list : [1, 3, 4, 5] The original string : gfg The list after appending is : [1, 3, 4, 5, 'gfg']
Method #2 : Using append()
This particular function can be used to perform the operation of appending string element to end of list without changing the state of string to list of characters.
# Python3 code to demonstrate working of # Appending String to list # using append() # initialize list test_list = [1, 3, 4, 5] # initialize string test_str = 'gfg' # printing original list print("The original list : " + str(test_list)) # printing original string print("The original string : " + str(test_str)) # Appending String to list # using append() test_list.append(test_str) # printing result print("The list after appending is : " + str(test_list)) |
The original list : [1, 3, 4, 5] The original string : gfg The list after appending is : [1, 3, 4, 5, 'gfg']
Recommended Posts:
- Python | Perform append at beginning of list
- Python | Append suffix/prefix to strings in list
- Python - Conditional String Append
- Python | Convert List of String List to String List
- Python | Convert list of string to list of list
- Python | Convert mixed data types tuple list to string list
- Python | Convert list of string into sorted list of integer
- Python | Convert list of numerical string to list of Integers
- Python | Convert string List to Nested Character List
- Python Program to convert List of Integer to List of String
- Python | Convert string enclosed list to list
- Python | Convert a string representation of list into list
- Python | Check if given string can be formed by concatenating string elements of list
- Python - Remove front K characters from each string in String List
- Python | Merge Tuple String List values to String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

