",python,python-3.x"/>

首页 > 解决方案 > 我如何在 <> "hi 中获取字符串"

问题描述

如何使用python获取尖括号内的字符串。我想要“helloeveryone.c”作为输出请让我知道我是 python 新手

标签: pythonpython-3.x

解决方案


Use String's find method:

In [565]: s = "hi<helloeveryone.c>"

In [567]: s[s.find("<")+1:s.find(">")]
Out[567]: 'helloeveryone.c'

Explanation:

Slice the string from index where you find < to the index of >.

EDIT:

Use split method:

In [572]: s[s.find("<")+1:s.find(">")].split('.')[0]
Out[572]: 'helloeveryone'

推荐阅读