这个python文件中的%o是什么?

2024-10-01 11:40:33 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是python的表达式。它将整数转换为二进制。在

>>>octtab = {'0':'000', '1':'001', '2':'010', '3':'011',
      '4':'100', '5':'101', '6':'110', '7':'111'}
>>>def bin1(d, width=0):
    "integer to binary (string)"
    s = "%o" % d
    b = ''
    for el in s:
        b += octtab[el]
    if width > 0:
        if len(s) > width:
            return b[:width]
        b = b.zfill(width)
    return b

我不知道%o的意思。提前谢谢:)


Tags: toforstringreturnif表达式def二进制