例如,
print "hello world"
Run Code Online (Sandbox Code Playgroud)
在屏幕中间而不是开始?示例输出如下:
hello world
Run Code Online (Sandbox Code Playgroud)
Python 3提供shutil.get_terminal_size(),您可以使用str.center空格来居中:
import shutil
columns = shutil.get_terminal_size().columns
print("hello world".center(columns))
Run Code Online (Sandbox Code Playgroud)
如果您不使用Python 3,请os.get_terminal_size()改用.
正如@ br1ckb0t所提到的,这在Python 2中不方便.但是,我建议改用Python 3,而不是使用不太方便的方法.
| 归档时间: |
|
| 查看次数: |
7480 次 |
| 最近记录: |