How to split integer input in python?

后端 未结 3 859
走了就别回头了
走了就别回头了 2021-01-26 00:41

If you write like

n = str(input())

n = n.split()

print(n)

That will work. But if you try to do it with integers, you will get



        
3条回答
  •  旧巷少年郎
    2021-01-26 00:50

    You can split integer value with following ways..

    1. list comprehension

      n = str(input())
      result = [x for x in n]
      print(result)
      
    1. using list object

       n = str(input())
       result = [x for x in n]
       print(result)
      
    2. using map object

       n = str(input())
       result = list(map(int,n))
       print(result)
      

提交回复
热议问题