The tab escape sequence \t
inserts a horizontal tab space in a string, which helps in formatting output by adding indentation or spacing between text.
\t
# Example 1: Simple tab space between words
print("Name:\tJohn")
# Output:
# Name: John
# Example 2: Tab used for columns alignment
print("Item\tPrice")
print("Pen\t$1.20")
print("Notebook\t$2.50")
# Output:
# Item Price
# Pen $1.20
# Notebook $2.50
# Example 3: Multiple tabs for more spacing
print("A\t\tB\t\tC")
# Output:
# A B C
# Example 4: Tab inside a sentence
print("Hello\tWorld!")
# Output:
# Hello World!
# Example 5: Using tab to format a list
items = "Apple\tBanana\tCherry"
print(items)
# Output:
# Apple Banana Cherry
Use the escape sequence \t
to insert horizontal tab spaces in strings for neat, readable, and aligned text output in Python programs.