how are strings immutable in python?
Lie.1296 at gmail.com
Tue Jul 8 12:53:17 CEST 2008
On Jul 7, 1:45 am, ssecorp <circularf... at gmail.com> wrote:
> >>> h = "aja baja"
# 'aja baja' is created and assigned to the name h
> >>> h += 'e'
# Is the equivalent of:
# h = h + 'e'
# In there, a h and 'e' is concatenated and assigned to
# a new string object which is bound to h. The
# original string object which contains
# 'aja baja' is "garbage collected".
> >>> h
# printing h which contains the new string object containing 'aja
> 'aja bajae'
 actually python uses reference counting first to choose which
object to delete
More information about the Python-list