In Python, one way to take input from a user for a list and then display the values of the list using a for loop is as follows:
main.py275 chars9 lines
In the above code, we are taking input from the user for the values of the list using the input()
function. We are then splitting the input string using the split()
method which returns a list of strings.
After that, we are using a for loop to iterate over each value of the list and then printing it using the print()
statement.
Note: Since the input()
function returns a string, we are using the split()
method to convert the string into a list of strings. If the user inputs integers or floats separated by space, we need to further convert them into the respective data types.
gistlibby LogSnag