Open kmr-srbh opened 3 months ago
In CPython, an assignment b = a stores the reference of a in b. This means that modifying a will reflect the changes in b. LPython however, creates a deep copy of the data structure, hence making it an independent entity.
b = a
a
b
from lpython import i32 main_list: list[i32] = [1, 2, 3, 4] copy_list: list[i32] = main_list print("Main List:", main_list) print("Copy List:", copy_list) main_list.append(5) print("Main List:", main_list) print("Copy List:", copy_list)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ python3 ./examples/example.py Main List: [1, 2, 3, 4] Copy List: [1, 2, 3, 4] Main List: [1, 2, 3, 4, 5] Copy List: [1, 2, 3, 4, 5]
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py Main List: [1, 2, 3, 4] Copy List: [1, 2, 3, 4] Main List: [1, 2, 3, 4, 5] Copy List: [1, 2, 3, 4]
In CPython, an assignment
b = a
stores the reference ofa
inb
. This means that modifyinga
will reflect the changes inb
. LPython however, creates a deep copy of the data structure, hence making it an independent entity.CPython
LPython