Strings (and numbers and tuples) are immutable : Variable Immutable « Language Basics « Python





Strings (and numbers and tuples) are immutable

Strings (and numbers and tuples) are immutable

#Strings (and numbers and tuples) are immutable: you can't modify them.

def change(n):
         n[0] = 'Changed'

names = ['A', 'B']
change(names)
print names

names = ['A', 'B']
n = names          # Again pretending to pass names as a parameter
n[0] = 'Changed' # Change the list
print names

names = ['A', 'B']
n = names[:]

print n is names

print n == names

n[0] = 'Changed'
print n

print names


change(names[:])
print names

           
       










Related examples in the same category

1.A tuple is an immutable listA tuple is an immutable list