python中的title()函数是python字符串方法,用于将每个单词中的第一个字符转换为大写,将字符串中的剩余字符转换为小写,并返回一个新字符串。
null
语法:
str.title()parameters:str is a valid string which we need to convert.return: This function returns a string which has first letter in each word is uppercase and all remaining letters are lowercase.
python
# Python title() Method Example str1 = 'geeKs foR geEks' str2 = str1.title() print 'First Output after Title() method is = ' , str2 # observe the original string print 'Converted String is = ' , str1.title() print 'Original String is = ' , str1 # Performing title() function directly str3 = 'ASIPU pawan kuMAr' .title() print 'Second Output after Title() method is = ' , str3 str4 = 'stutya kUMari sHAW' .title() print 'Third Output after Title() method is = ' , str4 str5 = '6041' .title() print 'Fourth Output after Title() method is = ' , str5 |
输出:
First Output after title() method is = Geeks For GeeksConverted String is = Geeks For GeeksOriginal String is = geeKs foR geEksSecond Output after title() method is = Asipu Pawan KumarThird Output after title() method is = Stutya Kumari ShawFourth Output after title() method is = 6041
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END