array = []
y = array.append(str(words2)) < another part of the program
Hash = y[0].count('#') # note the quotes and calling count on an element of the list not the whole list
print("There are", Hash, "#'s")
带输出:
>>> l = []
>>> l.append('#$%^&###%$^^')
>>> l
['#$%^&###%$^^']
>>> l.count('#')
0
>>> l[0].count('#')
4
不,这不是语言的一部分。你知道吗
编辑:我很确定你想用
y.count('#') # note the quotes
记住Python的一个优点是可移植性。编写一个只与自定义版本的解释器一起工作的程序将消除这种语言的优势。你知道吗
作为一个经验法则,任何时候你发现自己认为解决办法是重写部分语言,你可能朝着错误的方向前进。你知道吗
您需要对字符串而不是列表调用count:
带输出:
count
正在查找完全匹配的'#$%^&###%$^^'
!='#'
。您可以在如下列表中使用它:相关问题 更多 >
编程相关推荐