current position:Home>Python separates strings by length, and if not enough, 0 is added

Python separates strings by length, and if not enough, 0 is added

2022-07-25 10:14:37Wendianfei

For example, install string 8 Separate them in groups and print them

#!/usr/bin/python
#-*- coding:utf-8 -*-
in_str = raw_input()
if len(in_str) % 8 == 0:
	time = len(in_str) // 8
	for i in range(time):
		print in_str[i*8:i*8+8]
else:
	time = len(in_str) // 8
	for i in range(time):
                print in_str[i*8:i*8+8]
	print  in_str[time*8:]+"0"*(8-(len(in_str) % 8))

copyright notice
author[Wendianfei],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207250923073232.html

Random recommended