Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93160
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Could you explain "[1, 2, 3].remove(2)" to me? |
| Date | 2015-06-25 22:01 +0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <lf5lhf7vchx.fsf@ling.helsinki.fi> (permalink) |
| References | <e5890b67-939e-432a-b1ef-521bef393ae2@googlegroups.com> |
fl writes: > aa=[1, 2, 3].remove(2) > > I don't know where the result goes. Could you help me on the question? That method modifies the list and returns None (or raises an exception). Get a hold on the list first: aa=[1, 2, 3] *Then* call the method. Just call the method, do not try to store the value (which will be None) anywhere: aa.remove(2) *Now* you can see that the list has changed. Try it. By the way, it's no use to try [1, 2, 3].remove(2). That will only modify and throw away a different list that just happens to have the same contents initially. Try these two: aa=[1, 2, 3] bb=[1, 2, 3] # a different list! aa=[1, 2, 3] bb=aa # the same list! In both cases, try removing 2 from aa and then watch what happens to aa and what happens to bb.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Could you explain "[1, 2, 3].remove(2)" to me? fl <rxjwg98@gmail.com> - 2015-06-25 11:14 -0700 Re: Could you explain "[1, 2, 3].remove(2)" to me? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-25 12:37 -0600 Re: Could you explain "[1, 2, 3].remove(2)" to me? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-25 22:01 +0300
csiph-web