Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reversing the 'in' Operator in Python

If the following code equates to ‘True’:

'1234567' in '1234567:AMC'

Why won’t the opposite also indicate ‘True’? They both share the 1234567 character strings.

'1234567:AMC' in '1234567'

Is there a way this get this to say ‘True’ for the line of code above?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The str type has a .find() method with can be used.

The method returns the starting position of the found string, or -1 if not found.

For example:

'1234567:AMC'.find('1234567')

Returns 0. Indicating the primary string contains the substring starting at index 0. If the substring was not found, -1 would be returned.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading