【发布时间】:2013-04-29 08:33:00
【问题描述】:
我刚刚开始学习 Python,而且我绝对是个新手。
我开始学习函数了,我写了这个简单的脚本:
def add(a,b):
return a + b
print "The first number you want to add?"
a = raw_input("First no: ")
print "What's the second number you want to add?"
b = raw_input("Second no: ")
result = add(a, b)
print "The result is: %r." % result
脚本运行正常,但结果不是总和。即:如果我为'a'输入5,为'b'输入6,结果将不是'11',而是56。如:
The first number you want to add?
First no: 5
What's the second number you want to add?
Second no: 6
The result is: '56'.
任何帮助将不胜感激。
【问题讨论】:
-
非常感谢大家。因此,据我了解, a 和 b 作为字符串而不是整数返回,因此被连接而不是相加。谢谢!
-
附带说明,
add函数已经创建!from operator import add