***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***
***Use tabs for Content***

POSTS

    Testing Strings with in and not in

    In Python you can use the in operator to determine whether one string is contained in another string.

    general format of an expression using the in operator with two strings:

    string1 in string2

    The expression returns true if string1 is found in string2.

    Example:

    text = 'Four hundred and seven years ago'

    if 'seven' in text:

    print('The string "seven" was found.')

    else:

    print('The string "seven" was not found.')

    ‘not in’ operator can be used to determine whether one string is not contained in another string.

    Example:

    text = 'Four hundred and seven years ago'

    if 'seven' not in text:

    print('The string "seven" was not found.')

    else:

    print('The string "seven" was found.')