#34738: python可以靠右嗎


s11104220@school.saihs.edu.tw (施同學)


print(f"|{a:10}|{b:10}|")
b無法靠右
#34742: Re: python可以靠右嗎


cges30901 (cges30901)


print(f"|{a:10}|{b:10}|")
b無法靠右

靠右對齊要用'>'符號

可以改成print(f"|{a:10}|{b:>10}|")
https://docs.python.org/3.11/library/string.html#format-specification-mini-language

當然方法有很多種,用rjust也可以:print(f"|{a:10}|{b.rjust(10)}|")

甚至手動輸出空格:print(f"|{a:10}|{(10-len(b))*' '}{b}|")

#34746: Re: python可以靠右嗎


s11104220@school.saihs.edu.tw (施同學)


print(f"|{a:10}|{b:10}|")
b無法靠右

靠右對齊要用'>'符號

可以改成print(f"|{a:10}|{b:>10}|")
https://docs.python.org/3.11/library/string.html#format-specification-mini-language

當然方法有很多種,用rjust也可以:print(f"|{a:10}|{b.rjust(10)}|")

甚至手動輸出空格:print(f"|{a:10}|{(10-len(b))*' '}{b}|")

謝謝