>>> import string
>>> word = "hello."
>>> word2 = word.replace(string.lowercase, '.')
>>> print word2
hello.
I just want all the lowercase letters to turn into full stops.
What am I doing wrong here?
Use a regular expression:
from re import sub
print sub("[a-z]", '.', "hello.")
str.replace is looking for the string abcdefghijklmnopqrstuvwxyz to replace it with ., not looking for each individual letter to replace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With