HOW TO PRINT LIST IN PYTHON
Following are some methods for printing list in Python
- Using loops
- Without using loop
- Using map() and join()
Method 1: Using loop
a = [1, 2, 3, 4] for i in range(len(a)): print (a[i], end=" ") #printing a list of space-centered elements
Output:
1 2 3 4
Method 2: Without using loop
a = [1, 2, 3, 4] print(*a) print(*a, sep=', ')
Output:
1 2 3 4 1, 2, 3, 4
Method 3: Using map() and join()
a = [1, 2, 3, 4] print(" ".join(list(map(str,a))))
Output:
1 2 3 4
Subscribe
Login
Please login to comment
0 Discussion