0
Understanding this code
age = 23 new_age = age new_age -= 2 age += 2 print(age, new_age) #What minimal changes in this code do I make for ‘new_age’ and ‘age’ to have the same origin and to print an output of: 23 23
4 Antworten
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ I'm assuming it's an exercise/challenge to practice the difference between deep and shallow copying.
+ 1
Jenkins
Why are you doing such operation even you can just assign to new_age to get same value
age = 23
new_age = 23
print (age, new_age)
0
age = [23]
new_age = age
new_age[0] -= 2
age[0] += 2
print(age[0], new_age[0])
- 1
I don't know if this counts as minimal:
import numpy as np
age = np.array(23)
new_age = age
new_age -= 2
age += 2
print(age, new_age)