Exercises
Strings
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Print the number of characters in the word, then its first and last characters.
Python
word = "python"
# print the length, the first character, the last character
len() counts, [0] is the first, [-1] is the last.
word = "python"
print(len(word))
print(word[0])
print(word[-1])Exercise 2Passed
Check whether quick appears in the sentence, ignoring case. Print True.
Python
sentence = "The Quick brown fox"
# print whether quick is in it, ignoring case
Lowercase both sides before using in.
sentence = "The Quick brown fox"
print("quick" in sentence.lower())Exercise 3Passed
upper() does not change the original. Make word actually hold the uppercase version.
Python
word = "python"
word.upper()
print(word)Assign the result back to word.
word = "python"
word = word.upper()
print(word)