January 2019
Beginner
318 pages
8h 23m
English
Strings are immutable, meaning we can't change the values. Refer to the given example:
>>> welcome = 'Hello, John!'>>> welcome[0] = 'Y'TypeError: 'str' object does not support item assignment
As the strings are immutable; we cannot change an existing string. But we can create a new string that will be different from the original:
>>> str1 = 'Hello John'>>> new_str = 'Welcome' + str1[5:]>>> print(str1)Hello John>>> print(new_str)Welcome John>>>
Read now
Unlock full access