(python) I'm trying to get an input from the user (a sentence that contains many dots), and then split the sentence to a new line after each dot and capitalize every first letter of each line.
s=input("enter a sentence with donts\n")
csn=s.split(".")
for i in csn:
cap=csn.upper()
print(cap)
input:
i love.python.it's. great.
output I love Python I'ts Great how can I keep the dots? like this
I love.
Python.
It's.
Great.
You can use str.capitalize
to make the first chracter of each word a capital letter (if appropriate), and str.strip
to remove excess spaces:
print('\n'.join([i.strip().capitalize() for i in s.split('.')]))
prints
I love
Python
It's
Great
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.