输入输出

交互式输入input

在python3中的input会将用户输入的任何内容都存成str类型
name = input('请输入你的姓名:')
print(name,type(name))

请输入你的姓名:tony
tony <class 'str'>

Python2中则有raw_input和input两种方式。raw_input等效于py3中的input
2 不一样的是:python2的input要求使用者必须输入一个明确的数据类型,输入什么类型就存成什么类型

输出

占位符的使用

name = input('请输入你的名字:')
age = input('请输入你的年龄:')
print('My name is %s ,My age is %s'%(name,age))

结果:

请输入你的名字:msj
请输入你的年龄:25
My name is msj ,My age is 25

了解内容:%s接受的内容所有数据类型,%d则接受整形相关的类型。



原文地址:https://www.cnblogs.com/msj513/p/9641795.html