函数中输入多参数
def counts(*zifuchuan):length = len(str(zifuchuan))
return length
我是想定义这样一种情况,输入的多个参数,能够把它们转换为字符串,看看字符串的长度求大佬指点 举个例子 def counts(*zifuchuan):
return len(''.join())
逃兵 发表于 2021-9-13 10:26
def counts(*zifuchuan):
length = len(str(zifuchuan))
return length
这是我的函数 它的len是怎么计算的哇 我怎么看也看不懂呢
>>> counts(0,3.1415926,'sdfsdfsd','你好')
32
>>> counts(0,3.1415926)
14
>>> counts(3.1415926)
12
>>> counts('sdfsdfsd','你好')
18
>>> counts('sdfsdfsd')
13
>>> wodeai999 发表于 2021-9-13 10:30
def counts(*zifuchuan):
length = len(str(zifuchuan))
return length
它是将元组转化为字符串了
会多出来括号与逗号,甚至单引号 逃兵 发表于 2021-9-13 10:32
它是将元组转化为字符串了
会多出来括号与逗号,甚至单引号
def count(*zifuchuan):
new = ''.join(zifuchuan)
length = len(new)
print(new)
for i in range(length):
alpha = 0
space = 0
digit = 0
others = 0
for each in new:
if each.isalpha():
alpha +=1
elif each.isdigit():
digit +=1
elif each == ' ':
space +=1
else:
others +=1
print(alpha,digit,space,others)
您看下这个呢,我的输出有问题,比如 count('6576455','asdaeedfsdfs'),我只输出了1 0 0 0 wodeai999 发表于 2021-9-13 11:07
def count(*zifuchuan):
new = ''.join(zifuchuan)
length = len(new)
>>> count('6576455','asdaeedfsdfs')
6576455asdaeedfsdfs
12 7 0 0
页:
[1]