Worked Examples · Example 8.1
Q.Example 8.1: Create string variables str1, str2, str3 and str4, all having the same value 'Hello World!', by enclosing one or more characters in single, double or triple quotes.
Puducherry TnboardTextbookSubjective· 2mImportance★★★★★est
8% · 1/13 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →A Python string can be delimited by single ('), double (") or triple (''' or """) quotes; the delimiters are not part of the value, so all four variables hold exactly "Hello World!".
Idea. In Python, a string is a sequence of characters enclosed in quotes — and Python deliberately offers several quoting styles so that a quote character of the other kind can appear inside the text, and so that strings can span multiple lines (triple quotes). Which delimiter you use does not change the stored value.
str1 = 'Hello World!' # single quotes
str2 = "Hello World!" # double quotes
str3 = '''Hello World!''' # triple single quotes
str4 = """Hello World!""" # triple double quotes
print(str1)
print(str2)
print(str3)
print(str4)
print(str1 == str2 == str3 == str4) # they are all the same value
Output
Hello World!
Hello World!
Hello World!
Hello World!
True
Why each form exists:
- Single quotes — the everyday choice.
- Double quotes — convenient when the text itself contains an apostrophe: "Neerja's project". …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.