How to read formatted input in python?

前端 未结 4 714
再見小時候
再見小時候 2021-01-05 03:49

I want to read from stdin five numbers entered as follows:

3, 4, 5, 1, 8

into seperate variables a,b,c,d & e.

How do I do this in python?

4条回答
  •  鱼传尺愫
    2021-01-05 04:06

    If you print out a (the variable containing your input) you will find out, that a already contains a tuple. You do not have to split the contents.

    >>> a = input()
    3, 4, 5, 1, 8
    >>> print(a)
    (3, 4, 5, 1, 8)
    >>> type(a)

    >>> a[0]
    3
    >>> len(a)
    5

提交回复
热议问题