Python Practice › Tuple Programs › Program 43
Tuple of strings to integers
Write a Python program to convert a tuple of numeric strings to integers, ignoring stray commas.
Input
("4563", "68", "1,")Output
(4563, 68, 1)
Approach
- Strip the commas, then
int()each value.
Solution
t = ("4563", "68", "1,")print(tuple(int(s.replace(",", "")) for s in t))Output
(4563, 68, 1)
Learn the concept
New to this topic? Read the lesson, then come back.