python中print()怎样实现对齐
在Python中,可使用字符串的format()方法来控制打印输出的对齐方式。
例如,可使用以下的代码来左对齐打印输出:
print("{:<10}".format("hello"))
其中,<
表示左对齐,10
表示总的输出宽度为10个字符,如果字符串长度不足10个字符,则在右边填充空格。
同理,右对齐可使用>
,居中可使用^
,例如:
print("{:>10}".format("hello")) # 右对齐
print("{:^10}".format("hello")) # 居中对齐
tiktok粉丝购买:https://www.smmfensi.com/
TOP