How do you express binary literals in Python?

前端 未结 7 1841
囚心锁ツ
囚心锁ツ 2020-11-27 10:15

How do you express an integer as a binary number with Python literals?

I was easily able to find the answer for hex:

>>> 0x12AF
4783
>>         


        
7条回答
  •  囚心锁ツ
    2020-11-27 10:36

    I am pretty sure this is one of the things due to change in Python 3.0 with perhaps bin() to go with hex() and oct().

    EDIT: lbrandy's answer is correct in all cases.

提交回复
热议问题