In this python tuple program, we will convert a tuple of string values to a tuple of integer values.
Steps to solve the program
- Take a tuple of string values as input.
- Create an empty list.
- Use for loop to iterate over each value from the tuple.
- Add the value to the list using append() after converting it to the integer using int().
- Print the output.
tup = ('4563','68','1',)
print("Original tuple: ",tup)
l = []
for val in tup:
if type(val) is str:
l.append(int(val))
tup = tuple(l)
print("After converting to integers: ",tup)
Output :
Original tuple: ('4563', '68', '1')
After converting to integers: (4563, 68, 1)