Some Basic Python String Programs-2
Python Program to split a string into groups of n consecutive characters string = “Beta Python: Python for U” n = 5 split_string = [(string[ch:ch+n]) for ch in range(0, len(string), n)] #list comprehension print(split_string) #Output: [‘Beta ‘, ‘Pytho’, ‘n: Py’, ‘thon ‘, ‘for U’] List comprehension is a compact method that defines a list and … Read more