-1
D=int(input().split(","))
print(D)

TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

Dmitry
  • 6,716
  • 14
  • 37
  • 39
Ankur
  • 11
  • 1
  • 1
  • 2
    [From the docs](https://docs.python.org/3/library/stdtypes.html#string-methods) on `.split()` _"Return a list of the words in the string"_. You, I hope, know what a list is. You're trying to convert `['1','2']` to a int. [From the docs on `int()`](https://docs.python.org/3/library/functions.html#int) _"Return an integer object constructed from a number or string x"_. You've passed in a list which is invalid, hence the error. A list is an iterable so you could iterate through the list converting each element of the list to an integer. – Ben Dec 31 '17 at 08:14
  • You can use this:`D = list(map(int, input.split(',')))` to take multiple integers as input – tkhurana96 Dec 31 '17 at 08:34
  • you need `list(map(int, input().split(",")))` – Moinuddin Quadri Dec 31 '17 at 09:02

2 Answers2

0

Check if it is use-full to use

>>> x=input('Enter multiple inputs')
Enter multiple inputs 8,9,'ll',5
>>> x
"8,9,'ll',5"
x.split(',')
['8', '9', "'ll'", '5']
Sagar T
  • 89
  • 1
  • 1
  • 11
0

You are trying to convert a list to int.

string.split() returns a list.

 user_input = input('Enter Comma Seperated Digits:' ).split(',')
 #Enter Comma Seperated Digits:   1,2,3

 D = [int(x) for x in user_input]
 # This will return a LIST of integers.
 D= [1,2,3] #
 print type(D[0])
 # <class 'int'>
Darshan Jadav
  • 374
  • 1
  • 3
  • 15