Title in PythonThe title() method is used in Python to convert the first letter of the string to uppercase. In this article, we will discuss different programs to comprehend it's working.
The Basic ApproachSo let's begin with the first program. Output: String1 after conversion is: Software Development Life Cycle The original string is: soFTwaRe DevElOpMent LiFe CycLe String3 after conversion is: Artificial Intelligence String4 after conversion is: Data Science String5 after conversion is: Machine Learning Explanation- Let's have a glance at the explanation of this program,
In the second program, we shall see what will happen if it is used with a string that contains an apostrophe. Output: String1 after conversion is: Kenny'S Notebook Is With John The original string is: KeNNy's noTeBoOk iS wiTh JOhN String3 after conversion is: Let'S Celebrate The Colour Of Lights String4 after conversion is: Jimmy'S Favourite Is Subject Is Chemistry. String5 after conversion is: It'S Raining Today Explanation- It's time to understand what we have done in the above program, The approach is similar to the above program but in the above program only the first letters were converted to uppercase whereas here letter present after the apostrophe is also converted, this problem can be solved using regular expressions. Let us now see how title() can be used with NumPy. Title() with NumPyIn the third program, we will learn how NumPy can be used to convert the first letter to uppercase. The following program illustrates the same, Output: The values in the original array are: ['soFTwaRe DevElOpMent LiFe CycLe' 'ArtIfIcIAl IntEllIGence' 'DaTa scIEncE' 'mAcHiNe lEaRnInG'] The converted array is: ['Software Development Life Cycle' 'Artificial Intelligence' 'Data Science' 'Machine Learning'] Explanation-
At last, we will see the title() using pandas in Python Title() with PandasTo use the title() with pandas, we have taken a csv file that contains the student details- The program given below shows how it can be used, Output: Student Details Subject Code 0 Kim:Networking 129901 1 Peter:Software Engineering 129902 2 Rohan:Python Programming 129903 3 John:Operating Systems 129904 4 Sylvester:Data Structures 129905 Explanation-
ConclusionIn this article, we learned how the title() method can be used in Python.
Next TopicVariable Length Arguments in Python
|