str = input(tipmsg)
说明:a = input("Enter a number: ") b = input("Enter another number: ") print("aType: ", type(a)) print("bType: ", type(b)) result = a + b print("resultValue: ", result) print("resultType: ", type(result))运行结果示例:
Enter a number: 100↙
Enter another number: 45↙
aType: <class 'str'>
bType: <class 'str'>
resultValue: 10045
resultType: <class 'str'>
↙
表示按下回车键,按下回车键后 input() 读取就结束了。+
起到了拼接字符串的作用,而不是求和的作用。a = input("Enter a number: ") b = input("Enter another number: ") a = float(a) b = int(b) print("aType: ", type(a)) print("bType: ", type(b)) result = a + b print("resultValue: ", result) print("resultType: ", type(result))运行结果:
Enter a number: 12.5↙
Enter another number: 64↙
aType: <class 'float'>
bType: <class 'int'>
resultValue: 76.5
resultType: <class 'float'>
a = input("Enter a number: ") b = input("Enter another number: ") print "aType: ", type(a) print "bType: ", type(b) result = a + b print "resultValue: ", result print "resultType: ", type(result)在 Python 2.x 下运行该代码:
Enter a number: 45↙
Enter another number: 100↙
aType: <type 'int'>
bType: <type 'int'>
resultValue: 145
resultType: <type 'int'>
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有