>>split(x, one, two, three, fou-6ren">
gpt4 book ai didi

python - 按长度将字符串拆分为字符串?

转载 作者:IT老高 更新时间:2023-10-28 21:58:54 26 4
gpt4 key购买 nike

有没有办法把一个4*x个字符长的字符串,切成4个字符串,每个x个字符长,不知道长度字符串?

例如:

>>>x = "qwertyui"
>>>split(x, one, two, three, four)
>>>two
'er'

最佳答案

>>> x = "qwertyui"
>>> chunks, chunk_size = len(x), len(x)//4
>>> [ x[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
['qw', 'er', 'ty', 'ui']

关于python - 按长度将字符串拆分为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13673060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com