2024-09-28 16:53:37 发布
网友
我有不同长度的弦,例如:
text_1 = 'example' text_2 = 'a' text_3 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi.'
我必须给它们加上chars(any),因为文本的长度必须是16的倍数。在
我需要它来做这个:
我该怎么做?在
加上16和模的差
text_1 += ((16 - len(text_1) % 16)*'X')
这应该做到:
>>> s = 'fooo' >>> s += ' ' * (16 - (len(s) % 16)) >>> s 'fooo ' >>> len(s) 16
这里需要的字符数是16 - (len(s) % 16),因为len(s) % 16是长度除以16后剩下的字符数。在
16 - (len(s) % 16)
len(s) % 16
加上16和模的差
这应该做到:
这里需要的字符数是
16 - (len(s) % 16)
,因为len(s) % 16
是长度除以16后剩下的字符数。在相关问题 更多 >
编程相关推荐