Python: Print a list of space-separated elements
Python List: Exercise - 62 with Solution
Print Space-Separated List Elements
Write a Python program to print a list of space-separated elements.
Sample Solution:
Python Code:
# Define a list 'num' containing integers
num = [1, 2, 3, 4, 5]
# Use the '*' operator in a print statement to unpack the elements of the list 'num' as separate arguments
# This will print each element of the list separated by spaces
print(*num)
Sample Output:
1 2 3 4 5
Flowchart:
Python Code Editor:
Previous: Write a Python program to create a list of empty dictionaries.
Next: Write a Python program to insert a given string at the beginning of all items in a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/list/python-data-type-list-exercise-62.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics