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’ padded with ‘c’ to create a
string with a centered ‘s’ of length ‘n’. For example,
pad_with_n_chars(”dog”, 5, ”x”) should return the
string “xdogx“.
I should define a function pad_with_n_chars(s, n, c) that takes a string ‘s’, an
Share
With Python2.6 or better, there’s no need to define your own function; the string format method can do all this for you:
Using f-string:
f'{"dog":x^5}'