【新人求助】python 代码 对于 def 中 return 与 print 差别是什么?
注:(tab)也就是缩进代码(1)++++++++++++++++++++++++++++++++++x=1y=2defadd(x,y):(tab)z=x+y(tab)r...
注 :(tab)也就是缩进
代码 (1) ++++++++++++++++++++++++++++++++++
x = 1
y = 2
def add (x, y):
(tab)z = x + y
(tab)return z
print add(x,y)
代码 (2) ++++++++++++++++++++++++++++++++++
x = 1
y = 2
def add (x, y):
(tab)z = x + y
(tab)print z
print add(x,y)
输出结果 (相同) ++++++++++++++++++++++++++++++++++
>>> 3
问题 +++++++++++++++++++++++++++++++++++
输出结果一样,但 return 与 print 差别是什么 , 有什么利与弊 。 展开
代码 (1) ++++++++++++++++++++++++++++++++++
x = 1
y = 2
def add (x, y):
(tab)z = x + y
(tab)return z
print add(x,y)
代码 (2) ++++++++++++++++++++++++++++++++++
x = 1
y = 2
def add (x, y):
(tab)z = x + y
(tab)print z
print add(x,y)
输出结果 (相同) ++++++++++++++++++++++++++++++++++
>>> 3
问题 +++++++++++++++++++++++++++++++++++
输出结果一样,但 return 与 print 差别是什么 , 有什么利与弊 。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询