Introduction
Strings let us store and show words or sentences in programs. They help us work with text like names, messages, or any letters.
Jump into concepts and practice - no test required
string_variable = 'Hello, world!' string_variable = "Hello, world!" string_variable = '''This is a multi-line string.''' string_variable = """This is also a multi-line string."""
greeting = 'Hi there!' print(greeting)
quote = "She said, \"Hello!\"" print(quote)
multi_line = '''This is line one. This is line two.''' print(multi_line)
multi_line2 = """Line one. Line two.""" print(multi_line2)
name = 'Alice' welcome_message = f"Hello, {name}! Welcome to the program." print(welcome_message) multi_line_text = '''This program shows how strings work. You can write text in many ways.''' print(multi_line_text)
text = 'Hello' uses single quotes correctly. text = Hello misses quotes. text = Hello' has mismatched quotes. text = """Hello has unclosed triple quotes.text = '''Hello\nWorld''' uses triple quotes but escapes newline, so it shows literal \n. text = '''Hello
World''' uses triple quotes with actual newline, creating a true multi-line string.text = '''Hello World''' print(text)
text = 'It's a sunny day'
text = '''apple\nbanana\ncherry\n'''
# Fill in the blank:
d = {word: len(word) for word in _____}splitlines() and split('\n') include a trailing empty string ''. split() splits on all whitespace (including newlines) and discards empty fields. split(' ') ignores newlines.split() produces exactly {'apple':5, 'banana':6, 'cherry':6} without '' : 0.