A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079691.html below:

[Python-Dev] Slice as a copy... by design?

[Python-Dev] Slice as a copy... by design? [Python-Dev] Slice as a copy... by design?Gary Herron gherron at islandtraining.com
Thu May 22 17:35:35 CEST 2008
Facundo Batista wrote:
> Hi!
>
> A thread in PyAr raised the question that, considering that strings
> are immutable, why a slice of a string is a copy and not a reference
> to a part of that string.
>
> I couldn't answer why, so I'm asking here...Is it because the
> reference counting will be complicated? Is it because it'd be
> inefficient in other way? It's something else? Or is something that
> could be done... but is not done yet?
>
> Thank you very much!
>
>   

In fact, a slice is *not* always a copy!  In at least some (simple) 
cases, a slice references the original string:

 >>> s = 'abc'
 >>> t = s[:]
 >>> s is t
True
 >>> id(s)
3081872000L
 >>> id(t)
3081872000L

Gary Herron




More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4