标签:字符串 居中 img 字符 对齐 div ima for src
通过使用ljust(),center(),rjust()函数来实现输入字符串的左右对齐,居中,右对齐等操作;
print("|","Ursula".ljust(20),"|") # 左对齐
print("|","Ursula".center(20),"|") # 居中对齐
print("|","Ursula".rjust(20),"|") # 右对齐
方法二:(函数带参数,则以参数作为填充字符)
print("|","Ursula".ljust(20,"*"),"|") # 左对齐
print("|","Ursula".center(20,"*"),"|") # 居中对齐
print("|","Ursula".rjust(20,"*"),"|") # 右对齐
运行结果:
| **************Ursula |
| *******Ursula******* |
| Ursula************** |
————————————————
1 for i in range(1,50,2): 2 print((‘*‘*i).center(80)) 3 for i in range(1,10): 4 print((‘*‘*11).center(80))
标签:字符串 居中 img 字符 对齐 div ima for src
原文地址:https://www.cnblogs.com/bcyczhhb/p/11745173.html