Using String Methods in Python

Common String Methods:

Python provides several built-in string methods that allow you to manipulate and transform strings. Here are some common string methods:

Examples:

Let's see some examples of using string methods in Python:

        
            # Using .upper()
            message = "hello, world!"
            print(message.upper())

            # Using .lower()
            name = "John Doe"
            print(name.lower())

            # Using .capitalize()
            sentence = "python is fun"
            print(sentence.capitalize())

            # Using .title()
            title = "programming in python"
            print(title.title())

            # Using .replace()
            sentence = "I like apples."
            new_sentence = sentence.replace("apples", "bananas")
            print(new_sentence)

            # Using .strip()
            text = "   Hello, World!   "
            print(text.strip())

            # Using .split()
            fruits = "apple, banana, cherry"
            fruit_list = fruits.split(", ")
            print(fruit_list)

            # Using .join()
            words = ["Python", "is", "fun"]
            sentence = " ".join(words)
            print(sentence)
        
    

Using string methods in Python allows you to manipulate and transform strings easily, making your code more powerful and versatile.

String Methods YouTube Video