[Python] Catching multiple exception [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to cater for dual exceptions. E.g., in Python I have written:

    try:
    for loop:
    print the total_sum
    except:
    print("The entered string is not a number!")


    How do I include a second except to catch if the string is empty?

    I have tried:

    except:
    if my_substring == "":
    pring ("It is an empty string!")


    Default except must be last.

    It runs with a single exception but modifying or adding second fails with SyntaxError.

    Continue reading...

Compartilhe esta Página