How to Replace Value in Python List?
Hi Folks,
Today, I will let you know example of how to replace value in python list. step by step explain how to change value in python list. This article will give you a simple example of how to update value in python list. we will help you to give an example of how to modify value in list python. Alright, let us dive into the details.
If you want to change the value in a python list, then there are many ways to do this. I will give you a very simple example to modify the value in a python list. In this example, we will take list with [br] contain, then we will replace with <br />. we will use replace() to update string in python list. so, let's see the example with output:
You can use these examples with python3 (Python 3) version.
let's see below a simple example with output:
Example 1:
main.py
myList = ['Hi[br]', 'I', 'am', 'Hardik[br]', 'form', 'India[br]'] # Python List Change Value of Element Example newList = [elem.replace('[br]', '<br />') for elem in myList] print(newList);
Output:
['Hi<br />', 'I', 'am', 'Hardik<br />', 'form', 'India<br />']
I hope it can help you...