How did python escape?
Answers
Answered by
1
hayy mate here your answer ✔️ ✔️
____________________________
The book is confusing you by mixing two entirely different concepts.
\n is an escape sequence in a string literal. Like other \single-characterand \xhh or \uhhhh escape sequences these work exactly like those in C; they define a character in the string that would otherwise be difficult to spell out when writing code.
\ at the end of a physical line of codeextends the logical line. That is, Python will see text on the next line as part of the current line, making it one long line of code. This applies anywhere in Python code.
You can trivially see the difference when you print the results of strings that use either technique:
escape_sequence = "This is a line.\nThis is another line" logical_line_extended = "This is a logical line. \ This is still the same logical line." print(escape_sequence) print(logical_line_extended)
This outputs
This is a line. This is another line This is a logical line. This is still the same logical line.
Note that the line breaks have swapped! The \n escape sequence in the string value caused the output to be broken across two lines (the terminal or console or whatever is displaying the printed data, knows how to interpret a newline character), while the newline in the logical_line_extended string literal definition is gone; it was never part of the string value being defined, it was a newline in the source code only.
Python lets you extend a line of code like this because Python defines how you delimit logical lines very differently from C. In C, you end statements with ;, and group blocks of lines with {...} curly braces. Newlines are not part of how C reads your code.
So, the following C code:
____________________________
❤️⭐I hope you mark as brainlist answer⭐❤️✨✨✨
____________________________
The book is confusing you by mixing two entirely different concepts.
\n is an escape sequence in a string literal. Like other \single-characterand \xhh or \uhhhh escape sequences these work exactly like those in C; they define a character in the string that would otherwise be difficult to spell out when writing code.
\ at the end of a physical line of codeextends the logical line. That is, Python will see text on the next line as part of the current line, making it one long line of code. This applies anywhere in Python code.
You can trivially see the difference when you print the results of strings that use either technique:
escape_sequence = "This is a line.\nThis is another line" logical_line_extended = "This is a logical line. \ This is still the same logical line." print(escape_sequence) print(logical_line_extended)
This outputs
This is a line. This is another line This is a logical line. This is still the same logical line.
Note that the line breaks have swapped! The \n escape sequence in the string value caused the output to be broken across two lines (the terminal or console or whatever is displaying the printed data, knows how to interpret a newline character), while the newline in the logical_line_extended string literal definition is gone; it was never part of the string value being defined, it was a newline in the source code only.
Python lets you extend a line of code like this because Python defines how you delimit logical lines very differently from C. In C, you end statements with ;, and group blocks of lines with {...} curly braces. Newlines are not part of how C reads your code.
So, the following C code:
____________________________
❤️⭐I hope you mark as brainlist answer⭐❤️✨✨✨
Similar questions