Home > Software design >  How do I get a multicharacter output from input() function in Python
How do I get a multicharacter output from input() function in Python

Time:10-24

When input() is used, the resulting string considers the characters inside uniquely say:-

list(input(""))
1,2,3,4,5,78
['1', ',', '2', ',', '3', ',', '4', ',', '5', ',', '7', '8']

What if I want to get 78 as a result, What should I do?

CodePudding user response:

Try:

input("").split(",")

CodePudding user response:

You can use .split(',') to reformat the inputted string into a list of numbers (as strings). Like this:

l = input().split(',')

More Detail: The input function gets a string from the user, calling split on that string allows us to split the string into a list of values separated by a delimiter (here we used a comma). What you were doing in your original code was splitting the string into a list of individual characters. Read more on types here.

  • Related