2.7代码实现查询字符串内字符的数量
import string
def letterCount(str):
count = 0
for s in str:
if s.lower() in string.lowercase:
print()
count += 1
return count
question = "What is your name?"
print(letterCount(question))
但我用的是3.5,string.lowercase
找不到,查找后发现是做了改变。代码如下:
import string
def letterCount(str):
count = 0
for s in str:
if s.lower() in string.ascii_lowercase:
print()
count += 1
return count
question = "What is your name?"
print(letterCount(question))