Responsive Navbar with Google Search
☰ Menu
🏠 Home
Python
📄 LaTeX
📊 GNUPlot
💬 Feedback
✉️ Contact
Iterable Data Type: String
Iterable Data Type
List
Tuple
String
Loading Python Environment…
Python runs in your browser. Heavy or infinite loops may freeze your browser tab. Use "Stop" if needed; for heavy jobs, run locally.
Program 1
String
# Input string text = "Hello World" # Convert to uppercase uppercase_text = text.upper() print("Uppercase:", uppercase_text) # Convert to lowercase lowercase_text = text.lower() print("Lowercase:", lowercase_text)
Run
Stop
Output 1
Program 2
String
print("\n========== 1. CREATING STRINGS ==========") # Simple strings experiment = "Photoelectric Effect" unit = "eV" print("Experiment:", experiment) print("Unit:", unit) print("\n========== 2. STRING LENGTH ==========") print("Length of experiment name:", len(experiment)) print("\n========== 3. STRING INDEXING ==========") # Indexing (starts from 0) print("First character:", experiment[0]) print("Last character:", experiment[-1]) print("\n========== 4. STRING SLICING ==========") print("First 6 characters:", experiment[0:6]) print("Last 6 characters:", experiment[-6:]) print("Every second character:", experiment[::2]) print("\n========== 5. UPPERCASE & LOWERCASE ==========") print("Uppercase:", experiment.upper()) print("Lowercase:", experiment.lower()) print("Title Case:", experiment.title()) print("\n========== 6. REMOVING SPACES ==========") raw_data = " 9.81 m/s^2 " print("Raw:", raw_data) print("Strip:", raw_data.strip()) print("Left strip:", raw_data.lstrip()) print("Right strip:", raw_data.rstrip()) print("\n========== 7. STRING CONCATENATION ==========") quantity = "Energy" value = "5.2" combined = quantity + " = " + value + " " + unit print(combined) print("\n========== 8. STRING FORMATTING ==========") # Using f-strings (recommended) mass = 2.0 velocity = 3.0 print(f"Kinetic Energy depends on m = {mass} kg and v = {velocity} m/s") # Using format() print("Mass = {} kg, Velocity = {} m/s".format(mass, velocity)) print("\n========== 9. STRING REPLACEMENT ==========") formula = "E = mc2" print("Original:", formula) print("Corrected:", formula.replace("2", "^2")) print("\n========== 10. CHECKING SUBSTRINGS ==========") sentence = "Quantum mechanics is fundamental" print("Contains 'Quantum'?", "Quantum" in sentence) print("Contains 'Classical'?", "Classical" in sentence) print("\n========== 11. COUNTING CHARACTERS ==========") data = "aaaaabbbbcc" print("Count of 'a':", data.count("a")) print("Count of 'b':", data.count("b")) print("\n========== 12. FINDING POSITION ==========") equation = "V = IR" print("Position of '=':", equation.find("=")) print("Position of 'I':", equation.find("I")) print("\n========== 13. STARTS WITH / ENDS WITH ==========") filename = "experiment_data.csv" print("Starts with 'experiment'?", filename.startswith("experiment")) print("Ends with '.csv'?", filename.endswith(".csv")) print("\n========== 14. SPLITTING STRINGS ==========") measurement = "10.5,20.3,15.8" values = measurement.split(",") print("Split values:", values) print("\n========== 15. JOINING STRINGS ==========") joined = " | ".join(values) print("Joined values:", joined) print("\n========== 16. CHECKING STRING TYPE ==========") num_str = "12345" alpha_str = "Physics" print("Is digit?", num_str.isdigit()) print("Is alphabet?", alpha_str.isalpha()) print("Is alphanumeric?", "E2".isalnum()) print("\n========== 17. MULTILINE STRINGS ==========") theory = """ Newton's Laws: 1. Inertia 2. F = ma 3. Action = Reaction """ print(theory) print("\n========== 18. ESCAPE CHARACTERS ==========") print("Line1\nLine2") print("Tab\tSeparated") print("Quote: \"Photon\"") print("\n========== 19. STRING COMPARISON ==========") s1 = "laser" s2 = "LASER" print("Equal?", s1 == s2) print("Equal (case-insensitive)?", s1.lower() == s2.lower()) print("\n========== 20. LOOPING THROUGH STRING ==========") symbol = "EMW" for ch in symbol: print("Character:", ch) print("\n========== 21. STRING REVERSAL ==========") wave = "sine" print("Reversed:", wave[::-1]) print("\n========== 22. PRACTICAL PHYSICS EXAMPLE ==========") # Parsing a physics record record = "Mass=2.5kg;Velocity=4.0m/s" parts = record.split(";") for item in parts: print(item) print("\n========== END OF STRING OPERATIONS ==========")
Run
Stop
Output 2