A Python String is Immutable

preview_player
Показать описание
Discusses the immutable nature of a Python string
Рекомендации по теме
Комментарии
Автор

Thank you so much.. Lots of love from India

kumarprateek
Автор

a='ab-c'
b='ab-c'
a is b # False
a[0] is b[0], a[1] is b[1], a[2] is b[2], a[3] is b[3] #(True, True, True, True)

May i know the reason?

damodarsahu
Автор

a="Harry is"
print(a)
# a=3
print(id(a))
a=a+a[0]
print(a)
print(id(a))
a=a+a[1]
print(a)
print(id(a))

output:
Harry is
138136407467952
Harry isH
138136407498096
Harry isHa
138136407498096

why are the last two ids same?
shouldn't they be pointing to two different objects??

GoGetSP