题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
while True: try: want_str = input() want_str_len = len(want_str) if want_str_len % 8 == 0: count = int(want_str_len / 8) for each in range(0, count): print(want_str[8 * each:(8 * (each + 1))]) else: count = int(want_str_len / 8) remainder = want_str_len % 8 if count == 0: print(want_str + "0" * (8 - remainder)) else: for each in range(0, count): print(want_str[8 * each:(8 * (each + 1))]) print(want_str[count * 8:] + "0" * (8 - remainder)) except EOFError: break灵活使用字符串切片,注意切片最后一位不包括进去