Do these methods affect special characters?

Question

In the context of this exercise, do these methods affect special characters?

Answer

No, the methods in this exercise, .lower() .upper() and .title() will not affect special characters, which are any non-alphabetical and non-numeric characters. These methods will only apply to case-based characters, which include essentially all the alphabetical characters.

When applying these methods to strings with special characters, they will be treated similarly to how they apply to whitespace characters, which is also a type of special character, and one you might be familiar working with.

For example, here is how .title() would work for a string with some special characters,

string = "hello-world#!"
titled = string.title()

print(titled) # Hello-World#!

As we can see, each word, separated by a special character, was capitalized.

7 Likes

Well, if I may add: special characters have no ‘case’ to begin with so…
of course they won’t be affected by these methods.

Just try to think of a lowercase !, or a capital # ? :wink:

I do appreciate the example given though, and the similarity of treating them like whitespace.

2 Likes

What about letters with accents?

3 Likes

Good question!
I use those in my work quite a bit so I tried it out:

testing_accent_letters = "émèritus âunqüe" why_not_romanian = "bunĂ dimIneaȚa" and_even_turkish = "tAnıŞtıĞımA" print(testing_accent_letters) print(testing_accent_letters.upper()) print("") print(why_not_romanian) print(why_not_romanian.title()) print("") print(and_even_turkish) print(and_even_turkish.lower()) print("")

Seems to work fine :slight_smile:

16 Likes