函数的传入参数

""""
例如 len()
"""

str1 = "itheima"
str2 = "itcast"
str3 = "python"



"""count = 0
for i in str1:
    count += 1
print(f"字符串{str1}的长度是:{count}")

count = 0
for i in str2:
    count += 1
print(f"字符串{str2}的长度是: {count}")


count = 0
for i in str3 :
    count += 1
print(f"字符串{str3}的长度是: {count}")
"""

"""定义一个函数,避免代码重复。"""
def my_len(date) :
    count = 0
    for i in  date :
        count += 1
    print(f"字符串{date}的长度是: {count}")

my_len(str1)

 参数如不需要,可以省略

返回值如不需要,可以省略

函数必须先定义后使用

函数的传入参数


传入参数的功能是:在函数进行计算的时候,接受外部(调用时)提供的数据

def add (x,y) #x , y是形式参数
    result = x +y
    print(f"ix}+ {y}的结果是:{result}")


add(5,6)     5,6是实际参数

 
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值