问题:
想要让输出的字符能够按照左对齐,右对齐,居中对齐的格式排列
解决方法:
在Python中,是用str的rjust,ljust,center方法来实现上述的功能.看下面的例子:
>>> print '|', 'hej'.ljust(20), '|', 'hej'.rjust(20), '|', 'hej'.center(20), '|'
| hej | hej | hej |
>>> print 'hej'.center(20, '+')
++++++++hej+++++++++
相关说明:
ljust(...)
S.ljust(width[, fillchar]) -> string
Return S left justified in a string of length width. Padding is
done using the specified fill character (default is a space).
rjust(...)
S.rjust(width[, fillchar]) -> string
Return S right justified in a string of length width. Padding is
done using the specified fill character (default is a space)
center(...)
S.center(width[, fillchar]) -> string
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space)
分享到:
相关推荐
PythonCookbook3高清.pdf
这是 Python Cookbook 英文版的,需要的拿走吧
Python Cookbook(第3版)中文版.pdf 极清PDF
绍了Python应用在各个领域中的一些使用技巧和方法,从最基本的字符、文件序列、字典和排序,到进阶的面向对象编程、数据库和数据持久化、XML处理和Web编程,再到比较高级和抽象的描述符、装饰器、元类、迭代器和生成...
python cookbook(第3版)高清中文完整版.pdf,作者: David Beazley, Brian K. Jones 译者: 熊能 版本: 第3版 出版社: O’Reilly Media, Inc. 出版日期: 2013年5月08日 Copyright © 2013 David Beazley and ...
Modern Python Cookbook
python cookbook(第3版)高清中文完整版
Python Cookbook, 2nd Edition, Python Cookbook, 2nd Edition, Python Cookbook, 2nd Edition
Modern Python Cookbook 英文无水印pdf pdf使用FoxitReader和PDF-XChangeViewer测试可以打开
Python Cookbook.pdf
python cookbook 3th python cookbook 3th python cookbook 3th python cookbook 3th
PythonCookbook.zip
Python CookBook 3rd Edition, epub type file
python cook book 3th 中文版及英文版。 这本书的目标读者是那些想深入理解 Python 语言机制和最新编程技能的资深程序员。很多讨论都是标准库,框架和应用程序使用到的高级技术。... --- 摘至 python cookbook 3th
Python Cookbook 第二版 完整示例代码,Python Cookbook 第二版 完整示例代码
这本独特的食谱包含了用Python 3.3编写和测试的实用食谱,适合有经验的Python程序员,他们希望专注于现代工具和习惯用法。
《Python Cookbook》第二版英文版的epub格式,可以用移动设备或者kindle等电纸书阅读
Python Cookbook(第三版)中文,Python Cookbook(第三版)中文,Python Cookbook(第三版)中文
Maya Programming with Python Cookbook 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
python cookbook 中文版,欢迎python爱好者进行下载,谢谢