convert number to string in python

后端 未结 5 1530
你的背包
你的背包 2021-01-26 17:40

I meet a problem about converting number to string.

I want to get a string \"0100\" from str(0100), but what I got is \"64\". Does any way I can do to get a string \"010

5条回答
  •  生来不讨喜
    2021-01-26 18:01

    In Python2, a leading 0 on a numeric literal signifies that it is an octal number. This is why 0100 == 64. This also means that 0800 and 0900 are syntax errors

    It's a funny thing that's caught out many people at one time or another.

    In Python3, 0100 is a syntax error, you must use the 0o prefix if you need to write a octal literal. eg. 0o100 == 64

提交回复
热议问题