Avatar ·

Is there a Switch CASE operator in Python?

📁 python, вопрос, помощь, проект

n

I faced the fact that it is necessary to implement a multiple condition that in other languages ​​I would implement using the design & nbsp; switch-cse

n

in python, I have to sign everything through Conditions & NBSP; if -elif -else . This seems quite inconvenient to me.

n

is there a more convenient way to recording such conditions?

n

for example, I have units of measurement and depending on the selected I need to retu the corresponding factor:

n
   Def   get_multiplier  ( unit ): n  if  unit ==  'mm' : n  retu   10  **- 3  n  if  unit ==  '' cm ': n  Retu   10  **- 2  n  if  unit ==  'dm' : n  retu   10  **- 1  n  f  unit ==  'm' : n  retu   1  n  if  unit ==  'Km' : n  retu   10  **  3  n  raise  valueroror ( 'undefined unit: {}' .  format  (unit)) n   n