Return True if the given string contains an appearance of "xyz" where the xyz is not directly preceeded by a period (.). So "xxyz" counts but "x.xyz" does not.
时间: 2024-02-15 21:03:01 浏览: 13
你可以使用以下 Python 代码来实现该功能:
```python
def xyz_there(str):
for i in range(len(str)-2):
if str[i:i+3] == 'xyz':
if i == 0 or str[i-1] != '.':
return True
return False
```
这个函数使用一个循环来遍历字符串中的所有三个字符的子串。如果子串匹配 "xyz",则检查它是否是在字符串开头或者前面不是一个 "."。如果是,返回 True。如果没有找到匹配,返回 False。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)