Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHaben Gebremeskel
589 PointsUsing Python(3) in terminal in Visual Studio Code ---> .copy() will not work but [:] will
Just sharing something I encountered let me know if you guys had the same problem and solution
1 Answer
KRIS NIKOLAISEN
54,972 PointsWhat is your full version of Python. It looks like copy()
is available starting with version 3.3.
From my Visual Studio Code terminal (2.7.15 vs. 3.8.1)
kris$ python
Python 2.7.15 (default, Aug 22 2018, 16:36:18)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> i = ["a","b","c"]
>>> j = i.copy()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'copy'
>>> j = i[:]
>>> print(j)
['a', 'b', 'c']
>>>
kris$ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> i = ["a","b","c"]
>>> j = i.copy()
>>> print(j)
['a', 'b', 'c']