• Register
150 points
4

If you want to capitalize the first letter of each word in your python program then this tutorial for you. In this tutorial, we are going to discuss about the first letter capitalization in our python program. And also here we will discuss the approach behind this problem.

How we can Capitalize the First Letter Of each word or string?

If you want to capitalize the first letter in python then you need to use some method, modules, and approach otherwise we cannot make the first letter capital of each word in our code.
So there are different-different approaches for resolve this program but here we are using only two approaches.

1. tittle() method
2. capwords() using string module

What is the title() method in Python?

In python programming language title () is a method. And it is used for capitalized every first letter in Python programming language. You need to follow some given example code:-

Code:

>>> "kodlogs, australia".title()
'Kodlogs, Australia'
>>>

In the above code you can see that using the .title() method we can capitalize every string’s first letter.

What is capwords() in Python?

This method is also used to capitalize every first letter in a given string. If you want to use capwords() method then you need to import string and after we can use this method in our code.

Code:

>>> import string
>>> string.capwords("hey, are you a member of kodlogs coding community ?")
'Hey, Are You Member Of Kodlogs Coding Community ?'
>>>

 

150 points
4