简体   繁体   English

为什么即使我没有使用任何“str”命名变量,我也会收到(“str”函数不可调用)错误?

[英]Why am I getting ('str' function is not callable) error even though I haven't used any 'str' named variable?

originalMSG = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ']
codedMSG = ['v', 'u', '0', 's', '1', 'r', 'o', 'x', 'a', 'p', 'y', 'd', 'k', 'b', 'z', 'g', 'q', 'l', '5', ' ', 'w', 'c', 'm', '8', 'h', '4', 't', '3', '6', 'k', 'n', '7', 'j', '2', '9', 'e', 'i', 'f']
str2 = 'wello'
h=[]
#print(str2.index('w'))
for i in range(0, len(str2)):
    h=codedMSG(originalMSG.index(str2(i)))
print(str2)

It is giving me error in 8th line TypeError: 'str' object is not callable.它在第 8 行 TypeError 中给了我错误:'str' object is not callable。 in line 7在第 7 行

Replace str2(i) with str2[i] - indexing rather than callingstr2[i]替换str2(i) - 索引而不是调用

Also, do the same with codedMSG(...) - replace with codedMSG[...]此外,对codedMSG(...)执行相同操作 - 替换为codedMSG[...]

I think this is what you want to do:我认为这是你想要做的:

originalMSG = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ']

codedMSG = ['v', 'u', '0', 's', '1', 'r', 'o', 'x', 'a', 'p', 'y', 'd', 'k', 'b', 'z', 'g', 'q', 'l', '5', ' ', 'w', 'c', 'm', '8', 'h', '4', 't', '3', '6', 'k', 'n', '7', 'j', '2', '9', 'e', 'i', 'f']

str2 = 'wello'
h=[]

for i in range(0, len(str2)):
    h.append(codedMSG[originalMSG.index(str2[i])])
    
print(''.join(h))

Output: 2zmm4输出: 2zmm4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到“str”objet is not callable 错误? - Why am I getting a 'str' objet is not callable error? 即使使用str(),为什么仍打印'u'前缀? - Why are 'u' prefixes still printing even though I used str()? 我在这里收到错误错误是('str' object 不可调用) - I am getting errors here error is ('str' object is not callable) 为什么我得到:TypeError: unsupported operand type(s) for -: 'str' and 'str' 即使 dtypes 显示所有 float64 - Why am I getting: TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’ even though dtypes is showing all float64 即使我使用int,str类型错误 - str type error even though I am using int 当我运行此命令时,我收到TypeError:'str'对象不可调用..为什么呢? - When I run this , i am getting TypeError: 'str' object is not callable.. why is that? 为什么我收到 TypeError: 'str' object is not callable when using eval() on string that is python code - Why am I getting a TypeError: 'str' object is not callable when using eval() on string that is python code 为什么即使我不访问此文件夹也会收到此错误? - Why am I getting this error even though I don't even access this folder? 为什么我的按钮可以工作,即使我没有为其分配任何父窗口? - Why is my button working even though I haven't assigned any parent window to it? 为什么我得到不支持的操作数类型 -: 'str' 和 'str' 错误 - Why am I getting unsupported operand type(s) for -: 'str' and 'str' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM