首页 > 其他 > 详细

输入输出

时间:2018-09-14 21:25:12      阅读:172      评论:0      收藏:0      [点我收藏+]

交互式输入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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!