Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

strings are immutable in python

fruit = 'Banana'
fruit[0] = 'b'
# This will give us
# TypeError: 'str' object does not support item assignment
# That means we cannot change the original string
# But we can do the following
x = fruit.lower()
# The original string doesn't change, and we get only a copy of fruit
print(x)
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #strings #immutable #python
ADD COMMENT
Topic
Name
5+1 =