Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75291
| References | <cefbd1ff-b65f-43ec-947e-2324085a6486@googlegroups.com> |
|---|---|
| Date | 2014-07-27 14:37 -0700 |
| Subject | Re: What meaning of this ""hello %s you are %s years old" % x" |
| From | Dan Stromberg <drsalists@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12372.1406497047.18130.python-list@python.org> (permalink) |
On Sun, Jul 27, 2014 at 11:49 AM, fl <rxjwg98@gmail.com> wrote: > In Python, when should you use lists and when tuples? > > Sometimes you don't have a choice, for example if you have > > "hello %s you are %s years old" % x > then x must be a tuple. > > But if I am the one who designs the API and gets to choose the data types, then > what are the guidelines? You should use a tuple when you need something immutable (readonly), like a dictionary key. Immutable objects are good for hashing. You should use a list when you need something mutable (read/write), like appending over and over. Mutable objects are not good for hashing, because their hash value could change.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What meaning of this ""hello %s you are %s years old" % x" fl <rxjwg98@gmail.com> - 2014-07-27 11:49 -0700 Re: What meaning of this ""hello %s you are %s years old" % x" Gary Herron <gary.herron@islandtraining.com> - 2014-07-27 13:02 -0700 Re: What meaning of this ""hello %s you are %s years old" % x" Dan Stromberg <drsalists@gmail.com> - 2014-07-27 14:37 -0700 Re: What meaning of this ""hello %s you are %s years old" % x" Albert-Jan Roskam <fomcl@yahoo.com> - 2014-07-28 00:41 -0700 Re: What meaning of this ""hello %s you are %s years old" % x" Chris Angelico <rosuav@gmail.com> - 2014-07-28 17:58 +1000
csiph-web