3、
执行下列代码:
sentence = 'hello world'
print(sentence.rjust(2, '%'))
输出结果为()。
(3分)
A、hello world%%
B、、%%hello world
C、、%hello world%
D、、hello world
A、hello world%% ==》对应:print(sentence.ljust(13, '%')) 左对齐
B、%%hello world ==》对应:print(sentence.rjust(13, '%'))
C、%hello world% ==》 对应:print(sentence.ljust(12, '%'))
D、hello world
选D, rjust 使字符串按照给定宽度右对齐,且不满宽度的在左边填充指定字符
这里的宽度只有2,这里的指定字符是“%”,ABC对应的代码见上面的注释
rjust(self, width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).