Is there no switch function in Python

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Sep 10 09:14:37 EDT 2004


In article <CR20d.46131$Vf.2380522 at news000.worldonline.dk>,
Rudi Hansen <rsh_remove_this_ at pobox.dk> wrote:
>I dont seem to be able to find the switch statement in Python.
>
>I would like to be able to do
>
>switch(var)
>    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.
>
>if(var=1)
>    print "var =1"
>elseif(var=2)
>    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 chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "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