Home > Software design >  How to create try and else error handling for a tuple in case you have an integer
How to create try and else error handling for a tuple in case you have an integer

Time:08-24

How to set up a try and else for when having an integer inserted instead of a tuple

Tuple1 = (1,2,3)
Tuple2 = (4)
Tuple3 = (Tuple1   Tuple2)

'''

CodePudding user response:

If I understand correctly, this code should work

Tuple1 = (1,2,3)
Tuple2 = (4,2)

try:
    Tuple3 = Tuple1   Tuple2
except:
    Tuple3 = ()

CodePudding user response:

Tuple1 = (1,2,3)
Tuple2 = (4)

try:
    Tuple3 = Tuple1   Tuple2
except:
    Tuple3 = ()
    print ("Concatenation failed since one of the tuples is an integer")
else:
    print("Concatenation was successful")

finally:
    print (Tuple3)
  • Related