Python Practice › Loop Programs › Program 62
Display numbers from a list
Write a Python program to display the numbers of a list separated by commas.
Input
[1, 5, 8, 0, 4]
Output
1,5,8,0,4
Approach
- Print each number with
end=","except after the last one.
Solution
numbers = [1, 5, 8, 0, 4]for i, n in enumerate(numbers): end = "," if i < len(numbers) - 1 else "\n" print(n, end=end)Output
1,5,8,0,4
Line by line
Line 3
Every item except the last is followed by a comma.
Learn the concept
New to this topic? Read the lesson, then come back.