- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个代码:
variable = "FFFF"
message = bytearray( variable.decode("hex") )
message.len()
最佳答案
在 python 中用于此的习语是 len(obj)
,不是 obj.len()
>>> v = 'ffff'
>>> msg = bytearray(v.decode('hex'))
>>> len(msg)
2
__len__(self)
, 内置函数
len()
时会调用被调用并传递了你的类的一个实例。
(a) For some operations, prefix notation just reads better than postfix — prefix (and infix!) operations have a long tradition in mathematics which likes notations where the visuals help the mathematician thinking about a problem. Compare the easy with which we rewrite a formula like x*(a+b) into xa + xb to the clumsiness of doing the same thing using a raw OO notation.
(b) When I read code that says len(x) I know that it is asking for the length of something. This tells me two things: the result is an integer, and the argument is some kind of container. To the contrary, when I read x.len(), I have to already know that x is some kind of container implementing an interface or inheriting from a class that has a standard len().
关于python - 有没有办法知道python中bytearray变量的长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29304342/
我是一名优秀的程序员,十分优秀!