Py学习  »  Python

python列表中的count函数

emanuel • 3 年前 • 1162 次点击  

大家好,同志们,我想从输入中提取一个字符,并将其转换为一个列表,然后向用户显示每个索引的重复次数,但它给出了一个错误。

我的代码:

list = list(input("plase enter keyword"))

for item in list:
    print(f"value({item})"+list.count(item))

我的错误

TypeError 
Traceback (most recent call last)
c:\Users\emanull\Desktop\test py\main.py in <cell line: 3>()
      2 list = list(input("plase enter keyword"))
      4 for item in list:
----> 5     print(f"value({item})"+list.count(item))

TypeError: can only concatenate str (not "int") to str

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133765
 
1162 次点击  
文章 [ 3 ]  |  最新文章 3 年前