How to Replace Values in a List in Python? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Replacing values in a list in Python can be done by accessing specific indexes and using loops. In this article, we are going to see how to replace the value in a List using Python. We can replace values in the list in several ways. The simplest way to replace values in a list in Python is by using list indexing.Let’s take an example of replacing values in a list using list indexing. Python a = [10, 20, 30, 40, 50] # Replacing 30 to 99 a[2] = 99 print(a) Output[10, 20, 99, 40, 50] Let’s see other different methods to Replace Values in a List.Table of ContentUsing For LoopUsing While LoopUsing Lambda FunctionUsing Lambda FunctionIn this method, we use lambda and map function to replace the value in the list. map() is a built-in function in python to iterate over a list without using any loop statement. A lambda is an anonymous function in python that contains a single line expression. Here we gave one expression as a condition to replace value. Python a = [10, 20, 30, 40, 50] b = list(map(lambda x: 99 if x == 30 else x, a)) print(b) Output[10, 20, 99, 40, 50] Using For LoopWe can use for loop to iterate over the list and replace values in the list. We first find values in the list using for loop and if condition and then replace it with the new value. Python a = [10, 20, 30, 40, 50] for i in range(len(a)): if a[i] == 30: a[i] = 99 print(a) Output[10, 20, 99, 40, 50] Using While LoopWe can also use a while loop to replace values in the list. While loop does the same work as for loop. In the while loop first, we define a variable with value 0 and iterate over the list. If value matches to value that we want to replace then we replace it with the new value. Python a = [10, 20, 30, 40, 50] i = 0 while i < len(a): if a[i] == 30: a[i] = 99 i += 1 print(a) Output[10, 20, 99, 40, 50] How to Replace Values in a List in Python? Comment More info R rushi_javiya Follow Improve Article Tags : Python python-list Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 5 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 5 min read Python Tuples 4 min read Dictionaries in Python 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like