通过使用ljust(),center(),rjust()函数来实现输入字符串的左右对齐,居中,右对齐等操作;
print("|","Ursula".ljust(20),"|") # 左对齐
print("|","Ursula".center(20),"|") # 居中对齐
print("|","Ursula".rjust(20),"|") # 右对齐
运行结果:
| Ursula |
| Ursula |
| Ursula |
print("|","Ursula".ljust(20,"*"),"|") # 左对齐
print("|","Ursula".center(20,"*"),"|") # 居中对齐
print("|","Ursula".rjust(20,"*"),"|") # 右对齐
运行结果:
| **************Ursula |
| *******Ursula******* |
| Ursula************** |