How do i use string methods in python?



  • Python string method allow you to perform a task on a string.

    Lowercase all letters.

    upperhand = "Butter Fingers"
    print upperhand.lower()
    

    Result
    >> butter fingers

    Uppercase all letters.

    upperhand = "Butter Fingers"
    print upperhand.upper()
    

    Result
    >> BUTTER FINGERS

    The upper and lower are string methods and there are plenty more string methods available in python. A couple more are shown below.

    This shows the replace string method.

    >>> line = 'Blue moon on Kentucky'
    >>> print(line.replace('Kentucky', 'Jersey'))
    Blue moon on Jersey
    >>> 
    

    This shows the find string method. Character 13 is where Kentucky starts

    >>> line = 'Blue moon on Kentucky'
    >>> print(line.find('Kentucky'))
    13
    

Log in to reply
 

© Lightnetics 2024