Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can you change an element of a sequence in python?

1 Answer

0 votes
by (119k points)

We can change any element of a sequence in python only if the type of the sequence is mutable.

For example, if the sequence is a string, you cannot change the element.

Example:

String = “abcd”

String[1] = ‘e’ #will rise an error

For example, if the sequence is a list, you can change the element.

Example:

S = [‘a’, ‘b’, ‘c’, ‘d’]

S[1] = ‘e’  #is correct

I recommend enrolling in this Python Certification Course by Intelllipaat to learn Python.

Also, watch this video on Python Sequences:

Browse Categories

...