Python challenge No4

a='Mr.sha3ban'
b=a
print( f'the text is {a} id for a is: {id(a)}')
print( f'the text is {b} id for b is: {id(b)}')

If you run this code you will get the same Id for both variables
how can we change the id without changing the variable a and the string in both variables
in other word how to make b a copy not the same object?

2 Likes

The easiest way is to type out b = 'Mr.sha3ban'

Another way is to use any method or operation that destroys the old string and creates a new one. For example b = "".join(a)

2 Likes

yes you are right

this will be the way that destroys the old string and creates a new one
and also

b=a[::-1] [::-1]

2 Likes