输入
Python提供了 input() 内置函数从标准输入读入一行文本,默认的标准输入是键盘
str = input("请输入:"); #将输入内容存入字符串
print ("你输入的内容是: ", str)
输出
Python提供了print() 内置函数进行内容输出
- 格式化输出
# %s:代表字符串的占位 %d:整型
>>> name ='westos'
>>> age = 18
>>> print("%s的年龄是%d" %(name,age))
westos的年龄是18
>>> name ='python'
>>> print("%s的年龄是%d" %(name,age))
python的年龄是18
>>> age = 10
>>> print("%s的年龄是%d" %(name,age))
python的年龄是10
>>> print("%d的年龄是%d" %(name,age))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %d format: a number is required, not str
>>> print("%s的年龄是%s" %(name,age))
python的年龄是10
# %f:浮点型
# %.xf (x:1,2,3,4,5...)保留小数点后多少位
>>> money='4342432.12'
>>> name

这篇博客总结了Python的输入输出操作,包括使用input()函数获取用户输入,print()函数进行内容输出,以及str.format()方法进行格式化输出。详细介绍了print()的原始字符串使用以及str.format()的多种格式化方式。
最低0.47元/天 解锁文章
1071

被折叠的 条评论
为什么被折叠?



