[Tutor] Fwd: Difference between types

eryksun eryksun at gmail.com
Fri May 24 19:13:51 CEST 2013


On Fri, May 24, 2013 at 7:04 AM, Citizen Kant <citizenkant at gmail.com> wrote:
> Same happens with the tuple (100, 'value', 2);  where parenthesis and semi
> colon work as a rule, setting the shape of a value named tuple that's
> different to the shape of a value named list. At the same time both shapes
> are equal (since both are value).

A semicolon is an optional way to delimit statements in Python. It's
rarely used since stacking multiple statements on a single line gets
ugly fast.

A tuple is defined by commas, depending on context. However,
parentheses are typically required because commas have low precedence.

    >>> 1, 2 + 3, 4
    (1, 5, 4)

    >>> (1, 2) + (3, 4)
    (1, 2, 3, 4)

An empty tuple is a special case:

    >>> x = ()
    >>> type(x)
    <type 'tuple'>


More information about the Tutor mailing list