Taking Multiple inputs in list

Hey! I have some doubt regarding taking multiple values as input in one line. Mine doubt is how we get mutiple inputs of in a line of different data type and store it in list ? Can anyone help me with this. It would be really helpful :pray:
Eg.
I want to give below as input:

lst = [1, 3, 2, 1, 3, True, False, True, "apple", "mango", "banana", "apple"]

how do we get above as input and store in list?

When you use input() in python it takes input as a string regardless of what you enter as an input. You need to do some processing on the input entered.

1 Like

HOW do you want to give the input? Just write the entire thing down with the keyboard?
You can take the inputs in a loop and just append into an existing list. Then you might need some processing to adjust datatypes.
If you want to just input the entire thing at once, you can either do a lot of string operations (removing the [], split around ,) or if you assume the entire thing is written exactly like that: use eval(), which will treat a given string as Python code. Just be aware that eval() and it’s big bother exec() pose major security risks given a user could put any command in there.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.