Prev: Numericals (Integer, Float, Complex) | Next: random & math modules
s = 'spam'
e = 'eggs'
s + e, 'spam+eggs'
f = "foo"
s = 'spam'
boo = 2*f + " eggs " + s
boo
- a) Has a len() function that returns the string length in characters
- b) Is an indexed structure - Using indexes one can refer to specific string characters (we shall discuss indexing in depth in the 'list' section)
s = 'spam'
print(len(s))
print(s[0], s[3])
s[4]
# More examples on len() and string indexes
# Before running the code try to figure out the outcome
s = 'spam'
s2 = 'spam2'
s[0], s2[len(s)], s[len(s)-1], s[len(s+'1')-len(s2)]
. Free learning material
. See full copyright and disclaimer notice