小编Nik*_*dam的帖子

使用 casefold() 时,我收到错误消息“AttributeError: 'str' object has no attribute 'casefold'”

vowels = 'aeiou'

# take input from the user
ip_str = raw_input("Enter a string: ")

# make it suitable for caseless comparisions
ip_str = ip_str.casefold()

# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)

# count the vowels
for char in ip_str:
    if char in count:
        count[char] += 1

print(count)
Run Code Online (Sandbox Code Playgroud)

错误:

    Line - ip_str = ip_str.casefold()
AttributeError: 'str' object has no attribute 'casefold'
Run Code Online (Sandbox Code Playgroud)

python python-2.6 case-folding

4
推荐指数
1
解决办法
7002
查看次数

标签 统计

case-folding ×1

python ×1

python-2.6 ×1