my_str="welcome to plus2net.com"
print(my_str.capitalize()) # Welcome to plus2net.com
We can't change the first char if it is a number
my_str="345 is the number"
print(my_str.capitalize()) # 345 is the number
capitalize()
text = "hello world"
print(text.capitalize()) # Hello world
print(text.title()) # Hello World
print(text.upper()) # HELLO WORLD
Handling Special Characters:
text = "@welcome"
print(text.capitalize()) # @welcome (special character remains unchanged)
Applying to Multi-sentence Strings:
text = "hello. this is a test."
print(text.capitalize()) # Hello. this is a test.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.