[Python] Can I set a variable with the result of "match"?

Discussão em 'Python' iniciado por Stack, Junho 15, 2025.

  1. Stack

    Stack Membro Participativo

    Setting a variable with a match can be done simply like this:

    Mode = 'fast'
    puts = ''
    match Mode:
    case "slow":
    puts = 'v2 k5'
    case "balanced":
    puts = 'v3 k5'
    case "fast":
    puts = 'v3 k7'


    But can you do something like this?

    Mode = 'fast'
    puts = match Mode:
    case "slow": 'v2 k5'
    case "balanced": 'v3 k5'
    case "fast": 'v3 k7'


    Currently it results in a syntax error.

    Continue reading...

Compartilhe esta Página