We can capitalize the first letter of every word using the title() or capitalize() method. Example The following is an example of capitalizing a string in a file - f = open('capitalize.txt','w') f.write("welcome to tutorialspoint") f = open('capitalize.txt', 'r') for line in f...
# python program to capitalizes the# first letter of each word in a string# functiondefcapitalize(text):return' '.join(word[0].upper()+word[1:]forwordintext.split())# main codestr1="Hello world!"str2="hello world!"str3="HELLO WORLD!"str4="includehelp.com is a tutorials site"# ...
# Functions which aren't available as string methods. # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def". def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the ...
43 44 # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def". 45 def capwords(s, sep=None): 46 """capwords(s [,sep]) -> string 47 48 Split the argument into words using split, capitalize each 49 word using capitalize, and join the capitalized words using 50 joi...
"result=text[:1].upper()+text[1:7].lower()\+text[7:8].upper()+text[8:].lower()print(result)text="Kilometer"print(text.lower())old_string="hello python"new_string=old_string.capitalize()print(new_string)old_string="Hello Python"new_string=old_string.swapcase()print(new_string)...
Python String Method to Capitalize a word To capitalize the first letter of a string in python we usecapitalize()method.capitalize()method returns a new string in which the first letter of the string is capitalized. In this process, No change is made to the original string. ...
capitalize(...)| S.capitalize() -> string|| Return a copy of the string S with only...
15. Wrap word(s) in HTML tags. Write a Python function to create an HTML string with tags around the word(s). Sample function and result : add_tags('i', 'Python') -> 'Python' add_tags('b', 'Python Tutorial') -> 'Python Tutorial ' Click me to see the...
8. String capitalize() MethodThis method returns a string with only the first letter of the first word as uppercase.SyntaxHere is the syntax of the String capitalize() method:string.capitalize()ExampleThe following is the example demonstrating the usage of the capitalize() method:...
简介:本文包括python基本知识:简单数据结构,数据结构类型(可变:列表,字典,集合,不可变:数值类型,字符串,元组),分支循环和控制流程,类和函数,文件处理和异常等等。 Python基础知识点总结 一、开发环境搭建 二、基本语法元素 2.1 程序的格式框架 程序的格式框架,即段落格式,是Python语法的一部分,可以提高代码的...