Python variable is not persistent/ changes from unrelated bpy.ops line I want to store the rotation of an object to be able to change it back after some operations. From my little coding experience "rot" should stay persistent and not be changed in the next line by "bpy.ops.object.transform_apply". Am I missing something?

import bpy

obj = bpy.context.object

rot = obj.rotation_euler
print("store object rotation", rot)
#evaluates correct

bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)
print("rot after rotation-apply", rot)
#problem: rot has changed to (0, 0, 0)

#other operations

#problem: rotation cant be set back.
obj.rotation_euler = (rot)
print("gameobject_final_rotation: ",  obj.rotation_euler)
obj.rotation_euler is a reference to the rotation object which is affected by bpy.ops.object.transform_apply. In order to store the old rotation in a variable you can use:

rot = obj.rotation_euler.copy()