How to read formatted input in python?

前端 未结 4 744
再見小時候
再見小時候 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 03:55

    Under Python 2.x only (*)

    after a = input()

    a is a tuple with the 5 values readily parsed!

    A quick way to assign these 5 values is

    a, b, c, d, e = a
    

    (*) with Python version 3.0? or for sure 3.1, input() works more like the raw_input() method of 2.x, which makes it less confusing. (thank you mshsayem to point this out!)

提交回复
热议问题