首页 > 编程语言 > 详细

Python基础四

时间:2016-11-01 14:02:20      阅读:181      评论:0      收藏:0      [点我收藏+]

函数和过程

# -*- coding: utf-8 -*-
#函数
def func1():
    """testing1"""
    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)

 

以上代码运行结果

in the func1
in the func2
from func1 return is 0
from func2 return is None

 

函数调用

例一:

# -*- coding: utf-8 -*-
def test(x,y):
    print(x=%d%x)
    print(y=%d%y)

test(y=2,x=1)#关键字调用,与形参顺序无关

 

以上代码运行结果

x=1
y=2

 

例二:

# -*- coding: utf-8 -*-
def test(x,y):
    print(x=%d%x)
    print(y=%d%y)

test(1,2)   #位置参数调用,实参与形参位置一一对应

 

以上代码运行结果

x=1
y=2

 

例三:

# -*- coding: utf-8 -*-
def test(x,y,z):
    print(x=%d%x)
    print(y=%d%y)


test(3,z=2,y=6)#关键字要放在位置参数的后面

 

以上代码运行结果:

x=3
y=6

 

Python基础四

原文:http://www.cnblogs.com/xone/p/6018834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!