Python partial string questions, please.

Asked 2 years ago, Updated 2 years ago, 14 views

I'd like to take two strings and check if the first string is a partial string of the second string.

ex) First sentence: Bad person The second sentence: I am a bad person.
I'm a bad person.

First sentence: Ronaldo Second sentence: messironaldoneymar
ronaldo is a substring of messironaldoneymar

python

2022-09-21 16:33

1 Answers

s1 = 'ronaldo'
s2 = 'mess ronaldo'
if s1 in s2:
  print(s1, 'is a substring of', s2)

Add.

Do you include the def string (key, text):
      return key in text

s1 = 'ronaldo'
s2 = 'mess ronaldo'
Include if string (s1, s2):
  print ('%s is a substring '%s' of %s)

Please delete the duplicate questions.


2022-09-21 16:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.