我如何在整数前打印出一定数量的空格? [英] How do I print an integer with a set number of spaces before it?

查看:99
本文介绍了我如何在整数前打印出一定数量的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C的printf("%Xd", Y);仅打印整数X,并使其在控制台窗口上占据Y空格.

C has printf("%Xd", Y);, which just prints the integer X and makes it take Y spaces on the console window.

例如:

printf("%3d", 10);
console: " 10"`

printf("%5d", 5);
console: "    5"

如何在python 3中使用它?

How do I use this in python 3?

推荐答案

print("{0:10d}".format(5))在9个空格后将打印5. 有关使用python格式化的更多参考,请参考.

This print("{0:10d}".format(5)) will print 5 after 9 blanks. For more reference on formatting in python refer this.

这篇关于我如何在整数前打印出一定数量的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆