• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

165
Vistas
Is there a way to match inequalities in Python ≥ 3.10?

The new structural pattern matching feature in Python 3.10 is a very welcome feature. Is there a way to match inequalities using this statement? Prototype example:

match a:
    case < 42:
        print('Less')
    case == 42:
        print('The answer')
    case > 42:
        print('Greater')
over 3 years ago · Hanz Gallego
1 Respuestas
Responde la pregunta

0

You can use guards:

match a:
   case _ if a < 42:
      print('Less')
   case _ if a == 42:
     print('The answer')
   case _ if a > 42:
     print('Greater')

Another option, without guards, using pure pattern matching:

match [a < 42, a == 42]:
   case [True, False]:
      print('Less')
   case [_, True]:
      print('The answer')
   case [False, False]:
      print('Greater')
over 3 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda