input 2 variables separated by a comma in a single line

后端 未结 5 1336
长发绾君心
长发绾君心 2021-01-19 15:11

Is it possible to input 2 numbers int or float separated by a comma in a single line?

Say after the program runs it would ask the user to <

5条回答
  •  鱼传尺愫
    2021-01-19 15:48

    num1,num2 = map(float, raw_input('Enter a range: ').split(','))
    

    Alternatively, if you want to allow commas in the second value, use partition instead of split:

    s1,_,s2 = raw_input('Enter a range: ').partition(',')
    

    In this case, you'll have to convert the two strings to numbers by yourself.

提交回复
热议问题