Strings

Working with Strings

Strings are sequences of characters — text data. They can be created with single quotes, double quotes, or triple quotes for multi-line strings.
python
greeting = "Hello"
name = 'World'
message = f"{greeting}, {name}!"
print(message)  # Hello, World!

String Operations

Strings support many useful operations like concatenation, slicing, and built-in methods.
python
text = "Python Programming"

print(len(text))        # Length: 18
print(text.upper())     # PYTHON PROGRAMMING
print(text.lower())     # python programming
print(text[0:6])        # Slicing: Python
print(text.replace("Python", "Fun"))

F-Strings (Formatted Strings)

F-strings (available in Python 3.6+) are the easiest way to embed variables inside strings. Just prefix the string with f and use curly braces.
python
name = "Alice"
age = 30
print(f"{name} is {age} years old")
print(f"Next year, {name} will be {age + 1}")

Tip:F-strings are the modern way to format strings in Python. They're more readable than older methods like .format() or % formatting.

PlaygroundPython
Output
Click "Run" to see output

💬 Got questions? Ask me anything!