如果有一个像abcd或1234等字符串我怎么能一起打印,第一个字符,然后前两个字符,然后前三个等一起打印?
例如,string = 1234我想打印/返回1121231234或aababcabcd
到目前为止我有这个代码:
def string_splosion(str):
i = 0
while i <= len(str):
i += 1
print(str[:i])
print(string_splosion('abcd'))
Run Code Online (Sandbox Code Playgroud)
但它以单独的行打印/返回它.我可以手动编写它,print(str[0:1], str[1:2] <...>)但是如何让python做它因为我不知道字符串将会有多长?