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

28th Oct 2021, 6:38 PM
Jenkins
4 ответов
+ 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.
29th Oct 2021, 1:32 PM
Simon Sauter
Simon Sauter - avatar
+ 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)
29th Oct 2021, 1:58 AM
A͢J
A͢J - avatar
0
age = [23] new_age = age new_age[0] -= 2 age[0] += 2 print(age[0], new_age[0])
28th Oct 2021, 6:56 PM
Simon Sauter
Simon Sauter - avatar
- 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)
28th Oct 2021, 6:46 PM
Simon Sauter
Simon Sauter - avatar