python编程方式

#编程方式
'''
1.面向对象:----》类------》class
2.面向过程:----》过程----》def
3.函数式编程:--》函数----》def


函数:y=2x

python中函数定义方法:

def test(x):
    'The function definitions'
    x+=1
    return x

def:定义函数的关键字
test:函数名
():内可定义参数
'':文档描述(非必要,但是强烈建议为你的函数添加描述信息)
x+=1:泛指代码块或程序处理逻辑
return:定义返回值,并结束这个函数
'''

'''
#函数
def hs1():#   ():里面可以定义形参        
#    默认参数特点:调用函数的时候,默认参数非必须传递,例子(z=7软件目录结构规范)    
#    *args:接受N个位置参数(args可以是其他字母),转换成元组形式
#    **kwagsr:接受N个关键字参数(kwargs可以是其他字母),转换成字典的方式,实参格式('alex',age=34,sex='m',hobby='tesla')
    print('in the hs1')
    return 0
#过程
def hs2():
    print('in the hs2')

x=hs1()#   ():里面可以定义实参
y=hs2()

print('from hs1 return is %s' %x)
print('from hs2 return is %s' %y)
'''
发布了38 篇原创文章 · 获赞 0 · 访问量 257

猜你喜欢

转载自blog.csdn.net/weixin_44654782/article/details/104409517