0
How do I read an input seperated by spaces in python
Example: a user is to enter their favourite food and drink (seperated by spaces) and the program should read and display the food and drink
4 Antworten
+ 1
You need to split the input into a list. Here is an example:
https://code.sololearn.com/cD3yGMBN4nc3/?ref=app
+ 3
The input() function already reads whole lines, with spaces or not.
If what you want is separate out each, you can also call the split method on the string created from the input and create a list of the elements of the string according to a delimiter, in this case, a whitespace.
+ 2
and for spaces use this:
input().split(' ')
+ 2
I updated my code! I somehow misread 'spaces' for 'commas' LOL 😉