大家,早安。
我是Python的新手,应该说“我在学习这种语言时很开心”
我只是被这个复制功能卡住了
friends = ["kevin", "karen", "jim", "jim", "jim", "oscar", "toby"]
friends = friends.copy()
print(friends)
上面的命令将引发错误
friends2 = friends.copy()
AttributeError: 'list' object has no attribute 'copy'
I use Python 3.x and before posting this message I read few suggestions which pop up when I enter the title. I found a StackOverflow article wrote by @Shemogumbe The list.copy method does not work both in python 2.x and python 3.x
Also, it looked into Pythons Offical documentation on copy function
it also says use copied_list = original_list[:]
when I use this my VScode compiles without any error.
Hence my question is should I use friends2 = friends.copy()
or friends2 = friends[:]
and WHY
非常感谢每个可以帮助我的人。