Python - How to Create Copy of a List

x = [1,2,3]

y = x  --- y will reference the same list in memory as x

but if we want to make a new copy of list x and assign the reference to y use below

y = list(x)    --- this will make a copy of list x in memory and assign the reference to y


Comments

Popular posts from this blog

Python - How to Escape special characters in String

Python - Argument Passing