题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
li =[] s = input() num = len(s)%8 if num != 0: need = 8 - num s += need * "0" while len(s) != 0: li.append(s[:8]) s = s[8:] for s in li: print(s)
使用字符串切片来做
1. 先判断长度是否为8的整数
2.如果不是,则补齐对应的“0”
3.然后用切片工具,8个8个地切;存储在一个空列表里
4.输出