ManaTrick
ManaTrick
May 31, 2025 at 03:03 PM
Now, let's move to the next topic in the Python Coding: *Strings & String Methods* A string is a sequence of characters inside quotes. You can use: name = "Cherry" greeting = 'Hello!' paragraph = """This is a multiline string.""" 👉 Strings are immutable — once created, they can't be changed directly. ✨ *Common String Methods* *Here are some useful methods you’ll use all the time:* lower() → makes everything lowercase upper() → makes everything uppercase strip() → removes spaces from start and end replace("old", "new") → replaces parts of a string split() → splits text into a list of words count("word") → counts how many times something appears find("word") → finds the position of a word startswith("Hello") → checks how a string begins endswith("world") → checks how a string ends 🧪 *Examples* msg = " Python is Awesome! " print(msg.lower()) # python is awesome! print(msg.strip()) # Python is Awesome! print(msg.replace("Awesome", "Powerful")) # Python is Powerful! print(msg.split()) # ['Python', 'is', 'Awesome!'] 🛠️ *Project 1: Word Counter* text = input("Enter a sentence: ") words = text.split() print("Word count:", len(words)) Try it with: > Python is easy and powerful → Output: 5 🌀 *Project 2: Palindrome Checker* text = input("Enter a word: ") if text == text[::-1]: print("Palindrome!") else: print("Not a palindrome.") Try: - madam → Palindrome - racecar → Palindrome - hello → Not a palindrome *React with ❤️ once you’re ready for the quiz* ManaTrick: https://whatsapp.com/channel/0029VaLxL5o2v1IsQgjEKC2H

Comments