M
M
Maxim Yumikov2020-06-30 03:49:56
Python
Maxim Yumikov, 2020-06-30 03:49:56

How to delete from specific word to specific word?

Hey habr!
I'm not particularly new to Python, and not really a professional, something in between. I thought about how it is possible to remove everything unnecessary from a certain word to a certain word. Let me explain clearly:
Take for example

s = "Ваше имя - Максим, ваша фамилия  - Юмиков"
a = s[s.find("-") +2 : ]
print(a)
#  И тут оно отображает всё что дальше "-"

I need only Maxim to be displayed, without the text which is further

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2020-06-30
@OhMySenpai

string = "Ваше имя - Максим, ваша фамилия  - Юмиков"
answer = string[string.find("-") + 1:].strip()
answer = answer[:answer.find(',')].strip()
print(answer)

I didn’t quite understand what prevented me from repeating the same trick?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question