Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #14990

Re: How to isolate a constant?

References <f5539538-d079-4be1-b2c0-d98d3fc6a33f@h39g2000prh.googlegroups.com> <mailman.2138.1319330815.27778.python-list@python.org> <4EA71323.2030500@yahoo.com> <CALwzid=aWPuBGXw6g+10Z6FWRKXPm6f4syt7Q9UJCmisFCSk1g@mail.gmail.com> <j87j1j$hkc$1@dough.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-10-25 18:30 -0600
Subject Re: How to isolate a constant?
Newsgroups comp.lang.python
Message-ID <mailman.2221.1319589064.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Oct 25, 2011 at 6:08 PM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> Where's the line form to split those who'd prefer the first vs the
> second result in this sample <G>:
>
>>>> unExpected = "What about a string"
>>>> firstToLast = unExpected[:]

Strings are immutable.  That doesn't suffice to copy them, even
assuming you would want to do so in the first place.

>>> unExpected is firstToLast
True

If you find yourself needing to make a copy, that usually means that
you plan on modifying either the original or the copy, which in turn
means that you need a type that supports modification operations,
which usually means a list.  If you pass in a string and then copy it
with [:] and then try to modify it, you'll get an exception.  If you
don't try to modify it, then you probably didn't need to copy it in
the first place.

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to isolate a constant? Gnarlodious <gnarlodious@gmail.com> - 2011-10-22 17:26 -0700
  Re: How to isolate a constant? Chris Rebert <clp2@rebertia.com> - 2011-10-22 17:41 -0700
    Re: How to isolate a constant? Gnarlodious <gnarlodious@gmail.com> - 2011-10-22 18:01 -0700
      Re: How to isolate a constant? 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-22 22:12 -0700
      Re: How to isolate a constant? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-23 05:32 +0000
      Re: How to isolate a constant? Paul Rudin <paul.nospam@rudin.co.uk> - 2011-10-23 11:23 +0100
  Re: How to isolate a constant? MRAB <python@mrabarnett.plus.com> - 2011-10-23 01:46 +0100
    Re: How to isolate a constant? Alan Meyer <ameyer2@yahoo.com> - 2011-10-25 15:50 -0400
      Re: How to isolate a constant? Ian Kelly <ian.g.kelly@gmail.com> - 2011-10-25 14:05 -0600
      Re: How to isolate a constant? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-10-25 17:08 -0700
        Re: How to isolate a constant? Mel <mwilson@the-wire.com> - 2011-10-25 22:48 -0400
      Re: How to isolate a constant? Ian Kelly <ian.g.kelly@gmail.com> - 2011-10-25 18:30 -0600
  Re: How to isolate a constant? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-10-22 17:55 -0700

csiph-web