作者coeric (coeric)
看板Python
標題[問題] 問個很蠢的問題,原諒我
時間Fri May 25 16:15:27 2007
我自訂了一個函數
------------------
def f(x):
s = sin(2*x)
print s
a=f(1)
b=f(2)
print a+b
------------------
他卻無法加總,出現
Traceback (most recent call last):
File "/home/coeric/workspace1/電腦模擬/text.py", line 13, in <module>
print a+b
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
煩請各位大大用力批吧~~我想破頭就是不知道哪出問題
因為若我直接使用sin(1)+sin(2) 可以算阿~~
自訂函數後就不能算了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.109.8
推 Tiberius:print s -> return s 囧 05/25 16:22
推 coeric:非常感恩!!!我算是初學者,範例裡面沒說要打return... 05/25 17:04
→ coeric:我以為不用,經大大這麼一講,我想起PHP也要return...=.=" 05/25 17:05