Python_13_函数声明调用

# 在python中,函数定义一个函数,使用def语句,依次写出 def 函数名,括号,和括号中的参数,冒号
# 然后编写函数体,函数返回值用return,没有返回值则是none

def sys_print(args):    # 函数声明
    "函数说明"
    print(args)

sys_print("a")  # 函数调用
sys_print(1)    # 函数调用
sys_print(True) # 函数调用
sys_print(1.2)  # 函数调用

print("*"*20)

def sys1_print():   # 函数声明
    print("1")
    print("2")
    print("3")

sys1_print()    # 函数调用

print("*"*20)

def sys2_print(x,y,z):  # 函数声明
    print("print1 x={}".format(x))
    print("print3 y={}".format(y))
    print("print3 z={}".format(z))

sys2_print(1,"a",True)  # 函数调用


# 缺少参数
# 在函数参数中,如果参数有默认值,且外部函数没有传递该函数,那么形参直接获取默认参数的默认值
def sys3_print(x,y=2,z=3):
    print("print1 x={}".format(x))
    print("print2 y={}".format(y))
    print("print3 z={}".format(z))
    print("*"*20)

sys3_print(1)
sys3_print(1,"a")
sys3_print(1,"a",True)


'''
1.函数声明必须在调用之前
2.注意缺少参数的写法
3.函数没有使用return,默认none
'''

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值