Strings

Strings can be created using single quotes or double quotes. If you use three quote symbols in a row, you can make a multi-line quote. Do note that other than the hard returns, additional whitespace is ignored in multi-line quotes.

Strings can be concatenated using the “+” operator.

Python strings are actually just sequences of characters and can be accessed as such using individual character indexes, like “a[0]” or slice notation to grab a sub-string, like a[0:3].

[code lang=”python”]

#strings

a = “William”
b = ‘Burroughs’
c = “Shatner”
d = “”" of Orange
is not
a very popular
guy
in Ireland.”"”

print a
print b
print a
print c
print a + ” ” + b
print a + ” ” + c[0] + “.”
print a + ” ” + b[3] + b[0:2] + b[4:]
print a + d

[/code]

Leave a Reply