Python-输入输出
来源:互联网 发布:郑州关键词优化so82 编辑:程序博客网 时间:2024/04/29 20:54
总结几个常用的.
输入
Python提供了 input() 置函数从标准输入读入一行文本,默认的标准输入是键盘。
input 可以接收一个Python表达式作为输入,并将运算结果返回。
!/usr/bin/python3str = input("请输入:");print ("你输入的内容是: ", str)
输出
str.format()
(1)print('{}网址: "{}!"'.format('菜鸟教程', 'www.runoob.com'))
或者加上序号
print('{0}网址: "{1}!"'.format('菜鸟教程', 'www.runoob.com'))
(2)print('常量 PI 的值近似为 {0:.3f}。'.format(math.pi))
在 ‘:’ 后传入一个整数, 可以保证该域至少有这么多的宽度。 用于美化表格时很有用。
table = {'Google': 1, 'Runoob': 2, 'Taobao': 3} for name, number in table.items(): print('{0:10} ==> {1:10d}'.format(name, number))
填充常跟对齐一起使用
^、<、>分别是居中、左对齐、右对齐,后面带宽度
:号后面带填充的字符,只能是一个字符,不指定的话默认是用空格填充
下面代码可以解决中文填充问题
tplt = "{0:^10}\t{1:{3}^10}\t{2:^10}" print(tplt.format("排名","学校名称","总分",chr(12288)))
旧式字符串格式化
% 操作符也可以实现字符串格式化。 它将左边的参数作为类似 sprintf() 式的格式化字符串, 而将右边的代入, 然后返回格式化后的字符串. 例如:
import mathprint('常量 PI 的值近似为:%5.3f。' % math.pi)
%5.3f 的意思是将对应的变量按浮点数输出,在输出设备上占宽5个字符位右对齐,小数点后四舍五入保留3位小数
%.1f 小数点后保留一位
常量 PI 的值近似为:3.142。
阅读全文
0 0
- python输入输出
- Python输入输出
- python输入输出
- Python输入输出
- python输入输出
- Python 输入输出
- Python输入输出
- python 输入输出
- Python输入输出
- python 输入输出
- python输入输出
- Python输入输出
- Python输入输出
- Python输入输出
- python输入输出
- Python输入输出
- Python-输入输出
- python输入输出
- 三、箭头函数
- Js中盒子模型的样式获取
- [转]go-kit 入门
- mybatis枚举映射成tinyint
- Mac 私钥与公钥,基本命令
- Python-输入输出
- TX1上H.264编解码验证方案:OpenCV+GStreamer+H.264编解码
- TensorFlow:数据与参数的输入
- Codeforces Round #433 (Div. 2)A. Fraction
- 无密码登陆
- RecyclerView带padding的多功能分割线,允许取消指定分割线
- WPS协议阅读之第五章initial WLAN setup
- PHP的类,abstract类,interface及关键字extends和implements
- 始于足下,望君勉之