Convert a tuple of string values to a tuple of integer values

In this python tuple program, we will convert a tuple of string values to a tuple of integer values.

Steps to solve the program
  1. Take a tuple of string values as input.
  2. Create an empty list.
  3. Use for loop to iterate over each value from the tuple.
  4. Add the value to the list using append() after converting it to the integer using int().
  5. 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)
				
			

convert a string into a tuple.

convert a given tuple of integers into a number.

Leave a Comment