Python Program to Capitalize First Character of String

Python Program to Capitalize First Character of String

Python program to capitalize the first character of a string; Through this tutorial, you will learn how to capitalize the first character of a string in python.

Many times when you are working in Python or some other program langauge. So you have to do modification/manipulation etc. of strings. Today we will learn to capitalize strings first character or convert string first character/letter to uppercase in Python.

Python String capitalize()

Python capitalize method is one of the Python String Method, which is used to convert the first character into Uppercase and remaining characters to Lowercase and return a new string.

The syntax of capitalize() is:

string.capitalize()

capitalize() Parameter

The capitalize() function doesn’t take any parameter.

Return Value from capitalize()

The capitalize() function returns a string with first letter capitalized and all other characters lowercased. It doesn’t modify the original string.

Now you know that How to convert first character/letter of string to uppercase in Python. So now we discuss how to write a capitalize Function in Python programs with an example:

Example 1: Capitalize a Sentence

string = "python is AWesome."

capitalized_string = string.capitalize()

print('Old String: ', string)
print('Capitalized String:', capitalized_string)

Example 2: Non-alphabetic First Character

string = "+ is an operator."

new_string = string.capitalize()

print('Old String:', string)
print('New String:', new_string)

Recommended Python Posts

  1. Python Strings Example Tutorial
  2. Tuple Python with Example
  3. Python Modules: Learn Modules In Python
  4. Python Package (Create and Import) Example
  5. Built-In String Methods/Functions in Python With Example

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *