|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 dkzu 于 2018-1-29 15:19 编辑
- str1 = '''ABSaDKSbRIHcRHGdDIFa'''
- countA = 0 # 统计前边的大写字母
- countB = 0 # 统计小写字母
- countC = 0 # 统计后边的大写字母
- length = len(str1)
- for i in range(length):
- if str1[i] == '\n':
- continue
- if str1[i].isupper():
- if countB:
- countC += 1
- else:
- countC = 0
- countA += 1
- if str1[i].islower():
- if countA != 3:
- countA = 0
- countB = 0
- countC = 0
- else:
- if countB:
- countA = 0
- countB = 0
- countC = 0
- else:
- countB = 1
- countC = 0
- target = i
- if countA == 3 and countC == 3:
- if i+1 != length and str1[i+1].isupper():
- countB = 0
- countC = 0
- else:
- print(str1[target], end='')
- countA = 3
- countB = 0
- countC = 0
复制代码
请问最后那个and之前的 if i+1 != length是用来判断什么的,不加会造成什么后果?谢谢!
应该是判断是否是字符串最后一个元素 是不是到头儿了 要是不判断 就会异常
|
|