Use textwrap.wrap
:
>>> import textwrap
>>> s="aaaaaaaaaaaaaaaaaaaaaaa"
>>> textwrap.wrap(s, 4)
['aaaa', 'aaaa', 'aaaa', 'aaaa', 'aaaa', 'aaa']
More Related Contents:
- Python convert tuple to string
- Why are python strings and tuples are made immutable?
- converting string to tuple
- Convert a columns of string to list in pandas
- How does str.startswith really work?
- Concatenate elements of a tuple in a list in python [duplicate]
- What’s the difference between lists and tuples?
- Format timedelta to string
- How does swapping of members in tuples (a,b)=(b,a) work internally?
- How to get a string after a specific substring?
- Print string to text file
- How can I do multiple substitutions using regex?
- How to find char in string and get all the indexes?
- How to split strings into text and number?
- When are parentheses required around a tuple?
- Add Variables to Tuple
- Getting one value from a tuple
- Subtracting 2 lists in Python
- Multiline f-string in Python
- How to get the size of a string in Python?
- How to convert a string list into an integer in python [duplicate]
- Convert list of strings to dictionary
- Filter string data based on its string length
- Examples for string find in Python
- Is there a way to split a string by every nth separator in Python?
- Python Remove Comma In Dollar Amount
- How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?
- What does backward-slash b do in Python?
- Sort strings by the first N characters
- How to pad a string to a fixed length with spaces [duplicate]