我目前正在将一些 C++ 代码移植到 python,但没有找到如何翻译它:
print std::setfill('0') << std::setw(2) << std::hex << myVar << std::dec << " "
如何将 std::setfill('0')
和 std::setw(2)
翻译成 python?
最佳答案
没有直接的等效项,但您可以使用 format
函数转换要显示的每个值。参见 https://docs.python.org/2/library/string.html#format-specification-mini-language格式规范。
print '{:02x}'.format(myVar)
关于python - setfill 和 setw python 等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24165993/