Filipe Andrade Filipe Andrade - 1 year ago 83
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 Source

Use word in sentence. For example:

>>> 'el' in 'Hello'
>>> 'xy' in 'Hello'

For your reference, check: python in operator use cases

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download