Timeline for answer to How do I get a substring of a string in Python? by gimel
Current License: CC BY-SA 4.0
Post Revisions
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 19, 2020 at 15:26 | review | Low quality answers | |||
| May 20, 2020 at 3:46 | |||||
| Jan 2, 2019 at 16:23 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Used the actual title of the reference, etc.
|
| Nov 14, 2017 at 13:33 | review | Low quality answers | |||
| Nov 14, 2017 at 14:54 | |||||
| Oct 25, 2017 at 14:33 | comment | added | Aaron Hall♦ |
Attempting to sum up the other criticisms of this answer: In Python, strings are immutable, therefore there is no reason to make a copy of a string - so s[:] doesn't make a copy at all: s = 'abc'; s0 = s[:]; assert s is s0. Yes it was the idiomatic way to copy a list in Python until lists got list.copy, but a full slice of an immutable type has no reason to make a copy because it can't be changed, so there may as well be only one in memory and we shouldn't waste time copying it. Since this answer is wrong and doesn't even answer the question - should it be deleted?
|
|
| Jun 21, 2017 at 19:29 | comment | added | ShadowRanger |
@gimel: Actually, [:] on an immutable type doesn't make a copy at all. While mysequence[:] is mostly harmless when mysequence is an immutable type like str, tuple, bytes (Py3) or unicode (Py2), a = b[:] is equivalent to a = b, it just wastes a little time dispatching the slicing byte codes which the object responds to by returning itself since it's pointless to shallow copy when, aside from object identity tests, it's equivalent to just return another reference to one's immutable self.
|
|
| May 23, 2017 at 12:02 | history | edited | URL Rewriter Bot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
| May 22, 2017 at 21:52 | review | Low quality answers | |||
| May 23, 2017 at 9:48 | |||||
| Dec 30, 2016 at 21:21 | comment | added | bfontaine |
What’s the point since strings are immutable? a=b should be sufficient.
|
|
| May 29, 2013 at 14:31 | comment | added | gimel | The [:] full copy creates a NEW COPY, uses slice syntax and is read as "substring from start to end" | |
| May 29, 2013 at 13:48 | comment | added | Nicu Surdu | This has almost nothing to do with the question about substring. Doesn't even apply to string. Saying stringA = stringB is enough ... | |
| Mar 19, 2009 at 19:49 | history | edited | gimel | CC BY-SA 2.5 |
shallow
|
| Mar 19, 2009 at 18:02 | history | answered | gimel | CC BY-SA 2.5 |