Taking input for a list in Python can be done using the input()
function and some additional processing. Here are two examples:
Example 1:
numbers = input("Enter a list of numbers: ").split() numbers = [int(num) for num in numbers] print(numbers)
Input:
Enter a list of numbers: 1 2 3 4 5
Output:
[1, 2, 3, 4, 5]
Example 2:
words = input("Enter a list of words: ").split() print(words)
Input:
Enter a list of words: apple banana orange kiwi
Output:
[‘apple’, ‘banana’, ‘orange’, ‘kiwi’]