import streamlit as st # Set up the main layout of the app st.title("String Methods in Python") st.write(""" ### Explore various Python string methods interactively! Enter a string below, and choose the string method you want to apply. """) # User input: Input string user_input = st.text_input("Enter a string:", "Yes iam Batman!") # User input: Choose a string method option = st.selectbox( "Which string method do you want to apply?", ("upper", "lower", "capitalize", "title", "swapcase", "find", "replace", "split", "strip", "count") ) # Apply string method based on user selection if option == "upper": st.write(f"Result: {user_input.upper()}") elif option == "lower": st.write(f"Result: {user_input.lower()}") elif option == "capitalize": st.write(f"Result: {user_input.capitalize()}") elif option == "title": st.write(f"Result: {user_input.title()}") elif option == "swapcase": st.write(f"Result: {user_input.swapcase()}") elif option == "find": sub_str = st.text_input("Enter substring to find:") if sub_str: st.write(f"Position of '{sub_str}': {user_input.find(sub_str)}") elif option == "replace": old = st.text_input("Substring to replace:") new = st.text_input("Replacement substring:") if old and new: st.write(f"Result: {user_input.replace(old, new)}") elif option == "split": delimiter = st.text_input("Enter delimiter (leave empty for spaces):", "") st.write(f"Result: {user_input.split(delimiter)}") elif option == "strip": st.write(f"Result: {user_input.strip()}") elif option == "count": sub_str = st.text_input("Enter substring to count:") if sub_str: st.write(f"Count of '{sub_str}': {user_input.count(sub_str)}")