Is there no switch function in Python

Sion Arrowsmith siona at
Fri Sep 10 15:14:37 CEST 2004

In article <CR20d.46131$Vf.2380522 at>,
Rudi Hansen <rsh_remove_this_ at> wrote:
>I dont seem to be able to find the switch statement in Python.
>I would like to be able to do
>    case 1 :
>        print "var = 1"
>    case 2:
>        print "var = 2"

5 lines, 55 characters including the print statements.

>But it seems that i have to do.
>    print "var =1"
>    print "var=2"

4 lines, 52 characters (once corrected) including the print
statements (as written in the first example).

>Is ther no easier way?? 

In what way do you want it to be "easier"?

\S -- siona at --
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list