小编Ziu*_*Ziu的帖子

python的字符串格式中冒号的含义是什么?

在阅读Python的格式规范迷你语言时,

format_spec ::=  [[fill]align][sign][#][0][width][,][.precision][type]  
fill        ::=  <any character>  
align       ::=  "<" | ">" | "=" | "^"  
sign        ::=  "+" | "-" | " "  
width       ::=  integer  
precision   ::=  integer  
type        ::=  "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"   
Run Code Online (Sandbox Code Playgroud)

语法真让我困惑.

例如,如果我想将int转换为二进制表示,我可以这样做

"{0:b}".format(100)
"{:b}".format(100) # but this is fine too, so what dose the 0 do? …
Run Code Online (Sandbox Code Playgroud)

python

13
推荐指数
1
解决办法
3846
查看次数

使用位操作来计算两个数字的平均值?

我找到这段代码:

int mid = (l & r) + ((l ^ r) >> 1)
Run Code Online (Sandbox Code Playgroud)

这与以下相同mid=(l+r)/2

但我不明白为什么?

有什么帮助吗?谢谢!

bit-manipulation

2
推荐指数
1
解决办法
1048
查看次数

标签 统计

bit-manipulation ×1

python ×1