我試圖在python中創建的框中打印出一條消息,但不是直接打印,而是水平打印。如何在python中打印消息框
def border_msg(msg):
row = len(msg)
columns = len(msg[0])
h = ''.join(['+'] + ['-' *columns] + ['+'])
result = [h] + ["|%s|" % row for row in msg] + [h]
return result
預期結果
border_msg('hello')
+-------+
| hello |
+-------+
但得到
['+-+', '|h|', '|e|', '|l|', '|l|', '|o|', '+-+'].
有沒有辦法做到這一點,而不使用連接? – struggling
@struggling''+'+' - '* row +'+'' – user2728397