meaning of: line, =
Devin Jeanpierre
jeanpierreda at gmail.com
Fri Feb 6 08:09:05 EST 2015
Sorry for late reply, I somehow missed this email.
On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody <rustompmody at gmail.com> wrote:
> The reason I ask: I sorely miss haskell's pattern matching in python.
>
> It goes some way:
>
>>>> ((x,y),z) = ((1,2),3)
>>>> x,y,z
> (1, 2, 3)
>
> But not as far as I would like:
>
>>>> ((x,y),3) = ((1,2),3)
> File "<stdin>", line 1
> SyntaxError: can't assign to literal
>>>>
>
> [Haskell]
>
> Prelude> let (x, (y, (42, z, "Hello"))) = (1, (2, (42, 3, "Hello")))
> Prelude> (x,y,z)
> (1,2,3)
Yeah, but Haskell is ludicrous.
Prelude> let (x, 2) = (1, 3)
Prelude>
Only non-falsifiable patterns really make sense as the left hand side
of an assignment in a language without exceptions, IMO. Otherwise you
should use a match/case statement. (Of course, Python does have
exceptions...)
-- Devin
More information about the Python-list
mailing list