Python Practice › Tuple Programs › Program 43

Tuple of strings to integers

EasyTuple Programs · 43 of 70

Write a Python program to convert a tuple of numeric strings to integers, ignoring stray commas.

Advertisement
Input
("4563", "68", "1,")
Output
(4563, 68, 1)

Approach

  1. Strip the commas, then int() each value.

Solution

Python
t = ("4563", "68", "1,")print(tuple(int(s.replace(",", "")) for s in t))
Output
(4563, 68, 1)
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs