L suffix in long integer in Python 3.x

前端 未结 1 1364
离开以前
离开以前 2021-02-06 13:29

In Python 2.x there was a L suffix after long integer. As Python 3 treats all integers as long integer this has been removed. From What\'s New In Python 3.0:

<
1条回答
  •  耶瑟儿~
    2021-02-06 13:41

    You misunderstood the documentation.

    The remark is aimed at people trying to strip the L from repr() in Python 2. Those people could use str() instead and get the same number without having to strip the L each time.

    In other words, str(), when used on a long integer in Python 2, is the better method to convert the number to a string, as it will never add the L suffix that repr() would add:

    Python 2.7.6 (default, Apr 28 2014, 17:17:35) 
    [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print repr(1L)
    1L
    >>> print str(1L)
    1
    

    Python 3 will never add the L. Not when using repr(), and not when using str(). There would be no point; all integers in Python 3 are long integers.

    0 讨论(0)
提交回复
热议问题