String A string is an immutable sequence of characters. In Python, strings support indexing, slicing, and a rich set of built-in methods. Complexity Operation Time Index / Slice O(1) / O(k) Search (in, find) O(n) Concatenation O(n + m) Split / Join O(n) Python Usage # Slicing text = "PythonProgramming" text[:6] # "Python" text[-11:] # "Programming" # Case "hello".upper(); "HELLO".lower() # Find & Replace "hello".find("ll") # 2 "hello".replace("ll", "rr") # "herro" # Split & Join "a,b,c".split(",") # ['a', 'b', 'c'] "-".join(['a', 'b', 'c']) # "a-b-c" # Substring checks "Python" in "Hello, Python!" # True "banana".count("an") # 2 # Formatting f"My name is {name} and I am {age} years old." Related LeetCode Questions # Problem Difficulty Technique 14 Longest Common Prefix Easy Horizontal character scan 28 Find the Index of the First Occurrence in a String Easy Substring search 58 Length of Last Word Easy Reverse string traversal 151 Reverse Words in a String Medium Split, reverse, join 344 Reverse String Easy Two-pointer in-place swap