Filipe Andrade Filipe Andrade - 1 month ago 8
Python Question

Python check if string got a certain word (or combination of characters)

Ok so I have this string (for example):

var = "I eat breakfast."


What i would like to do is to check if that string has the letters "ea", and I wanted to be able to put those values into a list.

I tried using var[x] but I can only have one character at the same time and not a word right?

Answer

Use word in sentence. For example:

>>> 'el' in 'Hello'
True
>>> 'xy' in 'Hello'
False

For your reference, check: python in operator use cases

Comments