SAMG23
SAMG23

Reputation: 57

Split string after x characters using split()

I'm having issues splitting a string. I need it to be split after the first character and then after the following four, but I'm not sure on how to do it. As an example, for the input 123456789, I would need it to be split into ['1','2345','6789']. Any help would be appreciated.

Upvotes: 0

Views: 490

Answers (1)

Dmytro O
Dmytro O

Reputation: 477

>>> s = "123456789"
>>> s[0], s[1:5], s[5:]
('1', '2345', '6789')

Like this? Will format always be the same? Or is it anyhow conditional?

Upvotes: 1

Related Questions