Backward Slash Character

Share

What is the Backward Slash Character?

A backward slash character (\), abbreviated backslash, is a character of text typically used in text codes for addresses, used to separate elements in a path, and as a escape character in various programming languages.

Do not confuse the backslash character (\) with the forward slash character (/) or the pipe character (|).

Usage Examples

Windows Filepaths

On the Windows operating system, backslashes are used to separate drives, folders, and files in filepaths, e.g. C:\folder\sub-folder\file.txt.

Escape Character

In various programming languages, the backslash is used to start a escape sequence. The character that comes after the backslash will be escaped.

For example, in Python, to a string is delimited by double quotes ("). Like this:

print("Hello World!")

Above, print is a command known by Python, while Hello World! is arbitrary text.

In order to include a double quote (") inside this arbitrary text, we must escape it, because this character is also the character that Python uses to figure out where the arbitrary text starts and ends in the source code.

print("Hello \"World\"!")

In order to insert the backslash itself, we would have to type \\.

Escape sequences are commonly used to type whitespace characters. For example, \t is the tab character, \r is the carriage return character, and \n is the newline character.

Comments

Leave a Reply

Leave your thoughts! Required fields are marked *