Printing an int list in a single line python3

前端 未结 10 1395
臣服心动
臣服心动 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

    Yes that is possible in Python 3, just use * before the variable like:

    print(*list)
    

    This will print the list separated by spaces.

    (where * is the unpacking operator that turns a list into positional arguments, print(*[1,2,3]) is the same as print(1,2,3), see also What does the star operator mean, in a function call?)

提交回复
热议问题