为什么 rjust 方法不改变字符串?

Why does the rjust method leave a string unchanged?

我在 Python 3:

中有 2 个代码片段
print(b'3'.rjust(4, b'0'))

b'0003'
length = str(len("str")).encode() # length as bytes
length.rjust(4, b'0') # trying to pad length
print(length)

b'3'

据我了解,两者都应该产生与第一个片段相同的结果。为什么第二个代码段没有按预期工作?

length.rjust returns 一个新字符串。 Python 中的字符串不能就地修改。尝试:

length = length.rjust(4, b'0')