How to pad with n characters in Python

后端 未结 6 794
迷失自我
迷失自我 2020-12-28 13:29

I should define a function pad_with_n_chars(s, n, c) that takes a string \'s\', an integer \'n\', and a character \'c\' and returns a string consisting of \'s\'

6条回答
  •  有刺的猬
    2020-12-28 14:14

    It looks like you're only looking for pointers, not a complete solution. So here's one:

    You can multiply strings in python:

    >>> "A" * 4
    'AAAA'
    

    Additionally I would use better names, instead of s I'd use text, which is much clearer. Even if your current professor (I suppose you're learning Python in university.) uses such horrible abbreviations.

提交回复
热议问题