'''
原字符串左侧对齐, 右侧补零:
'''
str.ljust(width,'0')
input: '789'.ljust(32,'0')
output: '78900000000000000000000000000000'
'''
原字符串右侧对齐, 左侧补零:
方法一:
'''
str.rjust(width,'0')
input: '798'.rjust(32,'0')
output: '00000000000000000000000000000798'
'''
方法二:
'''
str.zfill(width)
input: '123'.zfill(32)
output:'00000000000000000000000000000123'
'''
方法三:
'''
'%07d' % n
input: '%032d' % 89
output:'00000000000000000000000000000089'
示例
def xyz_to_msg(x : int,y : int,z : int) -> str:
assert len(str(x)) <= 5, 'The length of x cannot be greater than 5!'
assert len(str(y)) <= 5, 'The length of y cannot be greater than 5!'
assert len(str(z)) <= 5, 'The length of z cannot be greater than 5!'
msg_x = str(x).rjust(5,'0') if x > 0 else '-' + str(-x).rjust(4,'0')
msg_y = str(y).rjust(5,'0') if y > 0 else '-' + str(-y).rjust(4,'0')
msg_z = str(z).rjust(5,'0') if z > 0 else '-' + str(-z).rjust(4,'0')
msg = msg_x + msg_y + msg_z
return msg