Last Updated: January 3, 2026
31 quizzes
Complete the code so that it takes the last 3 characters from the variable text and prints them.
print(text[:])Click an option to fill the blank:
Complete the code to split the variable sentence into words using spaces and count how many words there are.
word_count = len(sentence.(' '))Click an option to fill the blank:
Complete the code to create a raw string for a regular expression pattern that matches a digit followed by a word character.
pattern = "\d\w"Click an option to fill the blank:
Which statement about Python strings is TRUE?
Given s = "Hello", what does s[1] return?
Which slice returns the substring "World" from msg = "Hello World!"?
Which method removes whitespace from both ends of a string?
Which code correctly creates the string: He said "Hi"?
What is the main advantage of using join() over repeated concatenation with + for many substrings?
Which formatting style is generally recommended for new Python code because of clarity and performance?
Which raw string literal is valid in Python?
In a regular expression, what does the pattern ^[A-Z]+$ mean?
Given s = "python", which expression returns "pto"?
Which code uses str.format() to insert name and age into a sentence?
Order the steps to use a regex to find all email-like patterns in a text.
Drag and drop to reorder, or use the arrows.
Order the steps to create a formatted report line using an f-string.
Drag and drop to reorder, or use the arrows.
What is the output of this code?
1title = "Python Strings"
2print(len(title))What is the output of this code?
1s = "Hello, World!"
2print(s[-6:-1])What is the output of this code?
1text = " Clean Me "
2print(text.strip().upper())What is the output of this code?
1name = "Alex"
2age = 28
3print("{0} is {1} years old".format(name, age))What is the output of this code?
1pattern = r"\d+"
2text = "ID: 42"
3import re
4result = re.search(pattern, text)
5print(result.group())Find the bug in this code that formats a message with an f-string.
Click on the line(s) that contain the bug.
user = "Sam"score = 95message = f"User: {user}, Score: {score} points"print("message")Find the bug in this code that extracts a file extension using slicing.
Click on the line(s) that contain the bug.
filename = "report.pdf"extension = filename[-3:0]print(extension)Match each string method with what it does.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each regex token with its meaning.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to create a formatted log line that includes a level and a message using an f-string.
level = "INFO"message = "Startup complete"log_line = print(log_line)Click an option to fill blank 1:
Complete the code to normalize a username by trimming whitespace and converting to lowercase.
raw_username = " AdminUser "normalized = raw_username.().()print(normalized)Click an option to fill blank 1:
Complete the code to check if the given text starts with "Hello" in a case-insensitive way.
text = "Hello there"check = text.().startswith()print(check)Click an option to fill blank 1:
Complete the code to build a CSV line from three fields using join().
fields = ["Alice", "Developer", "Remote"]line = .join()print(line)Click an option to fill blank 1:
Click the line that uses a raw string to define a regex pattern.
Click on the line to select.
import repattern = "\d+" # pattern Araw_pattern = r"\d+" # pattern Btext = "Order 1234"print(re.findall(raw_pattern, text))Click the line where an f-string is used.
Click on the line to select.
name = "Jordan"role = "Engineer"info = f"{name} - {role}"print(info)