Tuples

Sami Hangaslammi shang.remove_edu at st.jyu.fi.edu
Wed Jan 26 17:50:29 EST 2000


Gerrit Holl <gerrit.holl at pobox.com> wrote in message
news:20000126221606.A962 at stopcontact.palga.uucp...

> With tuples, some things aren't really Pythonic. In some cases, even
> the Perl-like TMTOWTDI thing is true!

There's more than one way to write almost anything in almost any
language. You can ALWAYS add more parethesis if you like. For example
in C:

a = b + c is equivalent to a = (b + c)

> a = {}
> a[1,2] = 'f'
>
> is equivalent to:
> a = {}
> a=[(1,2)] = 'f'

The parenthesis are NOT part of the tuple syntax (except for zero and
one element tuples). They are just needed sometimes for different
grouping (just like parethesis usually are).

> And:
> "aaa %s bbb" % 'foo'
>
> is equivalent to:
> "aaa %s bbb" % ('foo',)

This is not a feature of tuples. The string format operator is defined
like this to make code prettier (i.e. to avoid the ugly (x,)-syntax).


--
Sami Hangaslammi
shang (at) st (dot) jyu (dot) fi

Get paid to surf the Web!
http://www.alladvantage.com/home.asp?refid=BOT021





More information about the Python-list mailing list