Python 3.9 First Character of String Uppercase

Python 3.9 First Character of String Uppercase

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.

In this post, we will discuss how to convert the first character/letter of string to uppercase.

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

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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