Python by example

Strings in Python

In Python, a string is a sequence of characters enclosed in single or double quotes. Strings are immutable, which means that once they are created, their value cannot be changed.

Here are some examples of strings in Python:

# Single-line string
name = "Romeo and Juliet"
# Multi-line string
quote = """
What's in a name? That which we call a rose
By any other name would smell as sweet.
"""

You can concatenate strings using the + operator:

first_name = "Romeo"
last_name = "Montague"
full_name = first_name + " " + last_name

print(full_name) # Output: Romeo Montague
Next example: Formatting