When Are String Indexes Used?


#1

What are some instances in the workplace that you’d use a string index for?


FAQ: Learn Python - Lists and Functions - Using strings in lists in functions
#2

Hi @gcook23,

Substrings come in handy when you need to get just part of a string. For example, if you have a URL and want to get just part of it, like a course name on Codecademy, you could trim out everything except that:

url_one = "https://www.codecademy.com/learn/learn-python"
url_two = "https://www.codecademy.com/learn/learn-ruby"

print("First course: {}".format(url_one[39:]))
# python
print("Second course: {}".format(url_two[39:]))
# ruby