May-15-2021, 01:15 AM
(This post was last modified: May-15-2021, 01:15 AM by BashBedlam.)
Here's one way to go about it using try and except and then parsing the error that is returned.
tester1 = ('this', 'and', 'that') tester2 = ['this', 'and', 'that'] def list_or_tuple (test_element) : try : test_element ['dummy'] except TypeError as error: return (error.__str__ ().split (' ') [0]) print (f'tester1 [0] is "{tester1 [0]}".') print (f'tester1 is a {list_or_tuple (tester1)}.\n') print (f'tester2 [2] is "{tester2 [2]}".') print (f'tester2 is a {list_or_tuple (tester2)}.')
Output:tester1 [0] is "this".
tester1 is a tuple.
tester2 [2] is "that".
tester2 is a list.