Jan-23-2024, 08:51 AM
hi
excuse me for this silly question, but i have problem with it. in below code :
how can I break the length line in the print command?
thanks
excuse me for this silly question, but i have problem with it. in below code :
""" shallowcopy and deepcopy from: https://realpython.com/python-mutable-vs \ -immutable-types/#common-mutability-related-gotchas """ import copy matrix = [[1, 2, 3], [4, 5, 6], [6, 7, 8]] shallow_copy = copy.copy(matrix) # Same as: matrix.copy() or matrix[:] deep_copy = copy.deepcopy(matrix) print(f"matrix is: {matrix}") print(f"id(matrix) is: {id(matrix)}") print(f"shallow_copy = copy.copy(matrix) , \ deep_copy = copy.deepcopy(matrix)") print(f"id(shallow_copy) is {id(shallow_copy)}") print(f"id(deep_copy) is {id(deep_copy)}") print(f"result of id(matrix[0]) == id(shallow_copy[0]) is : \ {id(matrix[0]) == id(shallow_copy[0]}") print(f"result of id(matrix[0]) == id(deep_copy[0]) is: { \ id(matrix[0]) == id(deep_copy[0])}") matrix[1][1] = 555 print(f"matrix[1][1] is set to 555") print(f"matrix is now: {matrix}") print(f"shallow_copy is now: {shallow_copy}") print(f"depp_copy is now: {deep_copy}")when I run it, I get the below:
Error:>>> %Run shallow_deep_copy_example1.py
Traceback (most recent call last):
File "D:\akb_python\akb_py_projects\shallow_deep_copy_example1.py", line 18
print(f"result of id(matrix[0]) == id(shallow_copy[0]) is : \
^
SyntaxError: unterminated string literal (detected at line 18)
>>>
I read on the net that \ is used for breaking lengthy lines, so I used it for breaking lines, but I encountered an error.how can I break the length line in the print command?
thanks