Quiz: Python Strings

Instructions

Complete and submit the following exercises:

# Set a different value for 'str' to get the right answer.
str = ''
# 1. Length
# The length should be 20
print("Length of str = ", len(str))
# 2. Positions
# This will display the second letter:
print(str[1])
# Now, show the third letter
# 3. Index
# Display the position of the first match with the letter a
# It should print 1
print("First position of the letter a = ", str.index("a"))
# 4. Count
# Count at least 5 letters a
print("It has ", s.count("a"))
# 5. Print in rows
# Print every letter of the string
# 6. For the next exercise, leave the value of `str` as it is
# and use methods to change the given string to lower case, 
# print it, then change it to upper case and print it
str = "HeLLo, hOW aRe YoU?"
# Tip: search for the different Python String Methods

Example of how a solution must be submitted

Here’s an example of how the solution should be laid out:

Let’s see the first exercise:

# Set a different value for 'str' to get the right answer.
str = ''
# 1. Length
# The length should be 20
print("Length of str = ", len(str))

Your solution will look like this:

# Set a different value for 'str' to get the right answer.
str = ''
# 1. Length
# The length should be 20
str = "twentycharactershere"
print("Length of str = ", len(str))