python | 'In' Keyword & "Not In" Keyword

python string in keyword
python string in keyword


"In"  Keyword

In keyword is Used for to check The character is present in String 


Example 

    str = " Take risks in your life, If you win, you can lead! If you loose, you can guide

                - Swami Vivekananda "


     print("life" in str)         

     print("Life" in str)         


Output

    True

    False



"In"  Keyword Used with If condition 

Example

    str = " Take risks in your life, If you win, you can lead! If you loose, you can guide - Swami                    Vivekananda "

    if "life" in str :

            print("Yes! Life is str")         

 

Output

    Yes! Life is str


"Not In"  Keyword

 Example 

         str = " Take risks in your life, If you win, you can lead! If you loose, you can guide

                - Swami Vivekananda "


       print("poor" in str)                     

       print("Poor" not in str)                     


Output

    False

    true


"Not In"  Keyword Used with If condition 

Example

    str = " Take risks in your life, If you win, you can lead! If you loose, you can guide - Swami                    Vivekananda "

    if "Life" not in str :

            print("Yes! Life is str")         

    else:

            print("No! Life is str")         


Output

    Yes! Life is str


Example - 2

    str = " Take risks in your life, If you win, you can lead! If you loose, you can guide - Swami                    Vivekananda "

    if "Life" in str :

            print("Yes! Life is str")         

    else:

            print("No! Life is str")         


Output

    No! Life is str



Also See


Post a Comment (0)
Previous Post Next Post