函数

'''
函数的意义
'''

#求每个字符串的长度  
str1="fqs123"
str2="doudou"
count=0
for i in str1:
     count+=1
print(str(count))
count=0

for i in str2:
     count+=1
print(str(count))
'''
函数

def 函数名(传入参数):
函数体
return 返回值
''' #求每个字符串的长度 str1="fqs123" str2="doudou" count=0 for i in str1: count+=1 print(str(count)) count=0 for i in str2: count+=1 print(str(count)) #使用函数优化这个过程 def my_len(data): count=0 for i in data: count+=1 print(f"字符串{data}的长度是{count}") my_len(str1) my_len(str2)

 

posted @ 2023-04-04 21:53  胖豆芽  阅读(11)  评论(0编辑  收藏  举报