pallas 发表于 2021-10-23 22:01:43

求助大佬pyehon中class的用法

大佬,我想问一下这个代码哪里有问题

class Solution:

            def romanToInt(self, s: str) -> int:
                        
                        代码

        def longestCommonPrefix(self, strs: list) -> str:

                        代码

报错:
Traceback (most recent call last):
File "C:\Users\mate\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\second.py", line 1, in <module>
    class Solution:
File "C:\Users\mate\AppData\Roaming\JetBrains\PyCharmCE2021.2\scratches\second.py", line 28, in Solution
    def longestCommonPrefix(self, strs: list) -> str:
TypeError: 'type' object is not subscriptable

大马强 发表于 2021-10-23 22:15:50

def longestCommonPrefix(self, strs: list) -> str;
把 str 换下,可能是命名冲突了
页: [1]
查看完整版本: 求助大佬pyehon中class的用法