Chapters
Python114 chapters

Exercises

String Methods

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Print True for each name ending in .png or .jpg, without a chain of or.

Python
for name in ["a.png", "b.txt", "c.jpg"]:
    # print the name and whether it is an image
    pass
Exercise 2

Print where two appears in the line, and how many times one appears.

Python
line = "one,two,one"
# print the index of two, then the count of one
Exercise 3

Split the setting on the first = only, into three parts, and print them.

Python
setting = "key=value=more"
# print the three parts of a partition