函数参数及调用

#函数
def func1():
    '''test1ing'''
    print("in the func1")
    return 0

#过程,就是没有返回值的函数
def func2():
    '''testing2'''
    print("in the func2")

x=func1()
y=func2()
print('from func1 return is %s' %x)
print('from func2 return is %s' %y)

 

return 的作用及效果:

def test1():
    print('in the test1')
    return 0    #执行后 结束函数,同时返回0这个值
    print('test end')

x = test1()
print(x)

  结果:

  in the test1
  0

 

函数返回值:

def test1():
    print('in the test1')
def test2():
    print('in the test2')
    return 0
def test3():
    print('in the test3')
    return 1,'hello',['alex','wupeiqi'],{'name':'alex'}
x = test1()
y = test2()
z = test3()
print(x)
print(y)
print(z)   #打印一个元组

总结:

  1. 没有return ,就返回None

  2. return一个数,就返回这个数

  3. return 多个数,就返回一个元组,包含着多个数

 

函数的返回值的作用?为什么要有返回值

因为我想要整个函数执行的结果是什么,后面的程序可能要根据这个结果进行不同的操作

 

posted @ 2017-08-22 09:32  _Cohen  阅读(103)  评论(0)    收藏  举报