Printing an int list in a single line python3

前端 未结 10 1361
臣服心动
臣服心动 2020-12-03 01:16

I\'m new to python and I\'m trying to scan multiple numbers separated by spaces (let\'s assume \'1 2 3\' as an example) in a single line and add it to a list of int. I did i

10条回答
  •  执笔经年
    2020-12-03 01:38

    Maybe this code will help you.

    >>> def sort(lists):
    ...     lists.sort()
    ...     return lists
    ...
    >>> datalist = [6,3,4,1,3,2,9]
    >>> print(*sort(datalist), end=" ")
    1 2 3 3 4 6 9
    

    you can use an empty list variable to collect the user input, with method append(). and if you want to print list in one line you can use print(*list)

提交回复
热议问题