How to repeat a string to up to specific length in Python

1 Answer

0 votes
def repeat_up_to_length(string, length):
    return (string * (length//len(string) + 1))[:length]

print(repeat_up_to_length('python', 22))  




'''
run:

pythonpythonpythonpyth

'''

 



answered Jul 19, 2022 by avibootz

Related questions

1 answer 157 views
2 answers 244 views
2 answers 227 views
227 views asked Dec 2, 2017 by avibootz
3 answers 180 views
180 views asked Apr 24, 2021 by avibootz
2 answers 244 views
...