【问题标题】:input integer and string in one line python [duplicate]在一行python中输入整数和字符串[重复]
【发布时间】:2018-11-02 01:01:31
【问题描述】:

如何从 python 中的一个输入行同时获取 int 和 string 输入 例子: 对于给定的行

10 I love coding

我想获得 10,我喜欢将编码作为单独的变量。我试过input().split(),但由于我和爱之间存在空间,所以会产生混乱

【问题讨论】:

    标签: python input


    【解决方案1】:

    你可以限制拆分:

    >>> input().split(maxsplit=1)
    10 I love coding
    ['10', 'I love coding']
    
    >>> a,b = input().split(maxsplit=1)
    10 I love coding
    >>> a
    '10'
    >>> b
    'I love coding'
    

    【讨论】:

    • 如果它像“我喜欢 10 编码”怎么办?
    猜你喜欢
    • 2016-07-14
    • 2015-04-29
    • 1970-01-01
    • 2011-02-18
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    相关资源
    最近更新 更多