Movatterモバイル変換
[0]ホーム
why does the % string format operator only take tuples?
Kragen Sitakerkragen at dnaco.net
Tue Apr 3 20:28:36 EDT 2001
In article <gha66glj2n4.fsf at synopsys.com>,Ram Bhamidipaty <ramb at synopsys.com> wrote:>Does anyone else think it would be a good idea of the % operator>were extended to also handle lists?No. Lists have the connotation that they could have any number ofelements and that there isn't much distinction between the elements(some come earlier, some later, but they're all the same kind of thingin some sense --- any code you could pass foo[0] to should also be ableto handle foo[1] if it's there). Tuples have the connotation thattheir elements have distinct meanings.Obviously, sequences that are the right operand of string % must haveexactly the right number of elements, and their elements are likely tohave different meanings (otherwise you'd use a loop instead of passingthem to the same %).These are stylistic matters, of course; Python will let you use yourtuples as immutable lists and your lists as mutable tuples. It'sprobably bad style to do this, though.The right argument of % can also be a dictionary.-- <kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>Perilous to all of us are the devices of an art deeper than we possessourselves. -- Gandalf the White [J.R.R. Tolkien, "The Two Towers", Bk 3, Ch. XI]
More information about the Python-listmailing list
[8]ページ先頭