【问题标题】:Python long integer inputPython长整数输入
【发布时间】:2014-01-11 07:43:51
【问题描述】:

如何在 Python 2.7 中接受“long int”输入?

附:我尝试了n=(*(raw_input())) 的各种变体,但无济于事。

【问题讨论】:

    标签: python python-2.7 input


    【解决方案1】:
    n = int(raw_input())
    

    这会将输入转换为整数。由于 Python 采用了任意精度的算法,我们不必担心数字有多大。

    >>> n = int(raw_input())
    100000000000000
    >>> n
    100000000000000L
    

    【讨论】:

    • Python 中有 long 类型,但它不同于 C 标准和类似标准的 long - 它具有任意精度,任何超出 int 精度的 int 对象变为 long>>> type(int(10000000000)) == long; True
    • @kroolik 谢谢 :) 从答案中删除。
    • @kroolik,(在 Python 2.x 中)。
    • @falsetru,是的。另外,链接到docs(第二段)
    猜你喜欢
    • 2012-11-13
    • 1970-01-01
    • 2014-03-28
    • 2016-03-25
    • 2021-01-21
    • 2020-08-02
    • 2015-02-24
    • 1970-01-01
    • 2016-07-14
    相关资源
    最近更新 更多