您的位置:首页 > 编程语言 > Python开发

python3.5变化(String)

2016-04-08 10:49 459 查看
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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: