Strings

Unit 05

At this point, you have already learned a fair bit about strings, most notably

f-strings

(f stands for format)

Strings and numeric objects can actually be combined a lot nicer and with more flexibility. Simply put an f in front of the quotes and directly use numeric objects in your string by enclosing them in curly brackets, like so:

color = "red"
f"I have {5} {color} apples"
'I have 5 red apples'

There are plenty of ways that you can use to format the appearance of the strings. You will notice a couple in the lecture material, but if you are interested to learn more, feel free to read Section 7.1.1 of the python documentation on f-strings.

Looping through strings

You can loop through strings just like you would expect,

word = "Banana"
for letter in word:
    print(letter)
B
a
n
a
n
a

More resources

Tip

I personally mostly need f-strings. Other string methods that I use regularly are, .find(), .split(), and .lower().

What you have learned so far should cover your needs. If you want to read up more, check out the Chapter Strings of the online course PY4E.