输入
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 =