The string type - interactive
The string type - interactive#
A string is made by enclosing something in quotes. Here are three different ways of making a string. All are allowed, and you’ll see all of them.
string1 = 'string1'
string2 = "string2"
string3 = """string3""" # Triple quotes
The first two are common with short strings. If you want a long string that spans several lines, or that contains quotes in it, you can enclose it in triple quotes.
EXERCISES Now let’s try some operations on strings. For each, think about what you expect, remembering that Python should try to do the most sensible thing if it can.
Can you add two strings?
Can you add a number to a string?
Can you multiply two strings?
Can you multiply a string by an integer?
If two strings have the same content, what happens if I do
string1==string2What happens if you do
string1>string2? Try with some test examples to figure out what’s going on. Discuss with us!