The following article contains programs to read a file and capitalize the first letter of every word in the file and print it as output. To capitalize the first letter we will use the title() function in python. The title function in python is the Python String Method which is used to convert the first character in each word to Uppercase and the remaining characters to Lowercase in the string and returns the new string.
# Content of the file serves as input Input: hello world Output: Hello World # Content of the file serves as input Input: geeks for geeks Output: Geeks For Geeks
- We will take the content of the file as input.
- We will open the file and save its content by using the open() function in python.
- Printing the content after altering it.
Below is the Implementation.
Geeksforgeeks Is A Computer Science Portal For Geeks. It Contains Well Written, Well Thought And Well Explained Computer Science And Programming Articles, Quizzes Etc.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.