首页 > 其他 > 详细

用户交互input

时间:2018-09-03 20:51:16      阅读:206      评论:0      收藏:0      [点我收藏+]

input() 函数
接收到的都是str,如果输入为数字,打印结果想进行运算,此时需要转义.
语法:
内容=input("提示信息")
这里可以直接获取到用户输入的内容.

a = input("请输入你的名字:")
print (type (a) ) #打印一下 a 的类型, 显示 class ‘str‘
print ("My name is "+a) 或者写成 print ("My name is ",a) 是一样的结果
假如用户输入的为数字,以上执行时数字不会进行计算,只是进行连接,,此时需要转义
例如
a = input("请输入一个数字:")
b = input ("请在输入一个数字:")
c = int(a)
d = int(b)
print (c + d)
也可以写成
a = int ( input ("请输入一个数字:"))
b = int ( input ("请再输入一个数字:"))
print ( type(a),type(b) )
print ( a + b )

用户交互input

原文:https://www.cnblogs.com/xiaozhangpython/p/9580762.html

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