Strings
String Assignment
Strings can start and end with either single or double quotation marks. For example "hello"
is the same as 'hello'
.
[13]:
string_1 = "abc123"
string_2 = 'abc123'
print(string_1)
print(string_2)
abc123
abc123
Multi-line Strings
Multi-line strings can be assigned by wrapping the string with three quotation marks.
[17]:
multi_line_string = """Multi-line strings are ok if your string
starts and ends with three quotation marks."""
print(multi_line_string)
Multi-line strings are ok if your string
starts and ends with three quotation marks.
Another way to assign multi-line strings to variables is to wrap the string in parenthesis like below and use the escape character \n
to create a new line.
[6]:
test = ("the first line is here\n"
"a second line is here\n"
"a third line is here")
print(test)
the first line is here
a second line is here
a third line is here
Escape Characters
[ ]: