31 - 讓字符串居中顯示

1. 如何讓字符串居中顯示,有哪些方法

  • center 方法
  • format 方法

2. 請使用center方法讓字符串居中顯示,兩側顯示 ‘#’

print('<' + 'hello'.center(30) + '>')
print('<' + 'hello'.center(30, '#') + '>')
<            hello             >
<############hello#############>
print('<{:^30}>'.format('hello'))
print('<{:#^30}>'.format('hello'))
<            hello             >
<############hello#############>

32 - 連接列表中的分隔符

發佈了128 篇原創文章 · 獲贊 128 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章