![]() So escape sequences are formed using two things: the first is a backslash (\\), and the second is the set of one or more characters following that backslash (\\). First see, how escape sequence works In the below example, we are using some of the escape sequence and their outputs, we are printing single quote ( \' ), double quotes ( \' ), printing path (double slash) ( \\) and using hexadecimal values ( \x ). ![]() A sequence is just a set of two or more characters and an escape where the sequence begins with a backslash (\\) and other characters in the set follow that backslash.Īn escape sequence is a sequence of characters that, when used inside a character or string, does not represent itself but is converted into another character or series of characters. So here comes the role of escape sequences.įirstly, understand sequences. Suppose you have the string containing a double backslash (\\\\), and you want to print the string with a double backslash, but it is impossible to print it directly. Introduction to Escape Sequence in Python ![]() In this article, you will learn how we can translate one character into another character or a sequence of characters that may be difficult or impossible to represent directly.You will understand most of the escape sequences with proper code outputs. This article will show you how to use escape sequences in Python.To do this, simply add a backslash ( \) before the character you want to escape. This character serves as an escape sequence initiator, and every character (one or more) following it is considered an escape sequence. Escape Sequences in Python Escape sequences allow you to include special characters in strings. In the escape sequence, a character is preceded by a backslash (\) followed by the character you want to represent for the new line. An escape sequence is a sequence of characters that, when used inside a character or string, does not represent itself but is converted into another character or series of characters that may be difficult or impossible to express directly, like newline (\n), tab (\t), and so on.
0 Comments
Leave a Reply. |