Text with special characters

To use special characters (", space, line break, etc.), as a developer, I need to use \ (escape characters)


Introduction

It is not possible to write " (a quotation mark) within a string:

print( "abc"def" )

because "abc" becomes the first string, while "def is not a string, because it doesn't end with a quotation mark.


To use a quotation mark the developer can write \" inside the string instead of just ":

print( "abc\"def" )

will give the following output:

abc"def

Same goes with variables:

text1 = "abc\"def"
print( text1 )

Line breaks

A line break can be written with \n:

print( "line1\nline2" )

output:

line1
line2

Tabs

A tab can be written with \t:

print( "column1\tcolumn2" )

output:

column1    column2

Instructions

-

Python code



Terminal output


Written by: Bartek / Bartlomiej Rohard Warszawski

?>