KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a Python program to demonstrate the difference between lists and tuples.

Python List Manipulation

3 Likes

Answer

# Demonstrating difference between List and Tuple

# Creating a list
my_list = [10, 20, 30]
print("Original List:", my_list)

# Updating list element
my_list[1] = 25
print("Updated List:", my_list)

# Creating a tuple
my_tuple = (10, 20, 30)
print("Original Tuple:", my_tuple)

my_tuple[1] = 25
# Trying to update tuple element (will cause error)

Answered By

2 Likes


Related Questions