Two values from one input in python?

前端 未结 18 2217
小鲜肉
小鲜肉 2020-11-28 03:46

This is somewhat of a simple question and I hate to ask it here, but I can\'t seem the find the answer anywhere else: is it possible to get multiple values from the user in

18条回答
  •  一向
    一向 (楼主)
    2020-11-28 04:12

    You have to use the split() method which splits the input into two different inputs. Whatever you pass into the split is looked for and the input is split from there. In most cases its the white space.

    For example, You give the input 23 24 25. You expect 3 different inputs like

    num1 = 23
    num2 = 24
    num3 = 25
    

    So in Python, You can do

    num1,num2,num3 = input().split(" ")
    

提交回复
热议问题