|  | 
 
| 
str1 = input('输入你要找的字符串:')
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 length = len(str1)
 for i in range(length-4):
 if str1.islower():
 if str1[i-1].isupper() and str1[i-2].isupper() and str1[i-3].isupper() and \
 str1[i+1].isupper() and str1[i+2].isupper() and str1[i+3].isupper():
 if str1[i+4].isupper() == False and str1[i-4].isupper() == False:
 print(str,end = '')
 
 
 Traceback (most recent call last):
 File "G:\phthon\练习\p20-2.py", line 9, in <module>
 print(str,end = '')
 TypeError: 'type' object is not subscriptable
 这个报错是什么原因哇
 
这个报错的意思就是你将不能进行索引的对象进行了索引
 
 将 print 这一行代码 str 改成 str1 即可,参考代码:
 
 
 复制代码
str1 = input('输入你要找的字符串:')
length = len(str1)
for i in range(length-4):
    if str1[i].islower():
        if str1[i-1].isupper() and str1[i-2].isupper() and str1[i-3].isupper() and \
        str1[i+1].isupper() and str1[i+2].isupper() and str1[i+3].isupper():
            if str1[i+4].isupper() == False and str1[i-4].isupper() == False:
                print(str1[i],end = '')
 可能是因为你拷论坛的代码,论坛会吧 [ i] 吞了变成斜体
 | 
 |