Python Practice › Loop Programs › Program 62

Display numbers from a list

EasyLoop Programs · 62 of 90

Write a Python program to display the numbers of a list separated by commas.

Advertisement
Input
[1, 5, 8, 0, 4]
Output
1,5,8,0,4

Approach

  1. Print each number with end="," except after the last one.

Solution

Python
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.

Advertisement

Learn the concept

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

More loop programs

← All 90 Loop Programs