Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Python capitalize

by suresh

Python capitalize function is used to convert the first character into Uppercase and remaining characters to Lowercase and return a new string. In this section, we discuss how to write a capitalize Function in Python Programming with an example.

The string capitalize function keeps the Non-letters unchanged. The syntax of the Python capitalize function is

String_Value.capitalize()

String_Value: Please select the valid String variable, or you can use the String directly.

Python capitalize method Example

The following set of examples help you understand the capitalize Function.

# Python Capitalize Method Example

Str1 = 'learn PYTHON AT tutOrial gateWay'

Str2 = Str1.capitalize()
print('First Output after Capitalize() method is = ', Str2)

# Observe the Original String
print('Converted String is = ', Str1.capitalize())
print('Original String is = ', Str1)

# Performing Capitalize() function directly
Str3 = 'pYTHON proGramminG'.capitalize()
print('Second Output after Capitalize() method is = ', Str3)

Str4 = 'pyTHon 1234 tuTorIal'.capitalize()
print('Third Output after Capitalize() method is = ', Str4)

Str5 = '12345'.capitalize()
print('Fourth Output after Capitalize() method is = ', Str5)
Python Capitalize

The following statement converts the above string into the capitalizing case using capitalize function and prints the output.

Str2 = Str1.capitalize()
print('First Output after Capitalize() method is = ', Str2)

The Python capitalize function returns the output in a new string instead of altering the original string.

print('Converted String is = ', Str1.capitalize())
print('Original String is = ', Str1)

From the above screenshot, you can observe that the original string Str1 is unchanged. If you want to change the original String, then you can write the following Python statement.

Str1 = Str1.capitalize()

The string capitalize function converts the First letter into Uppercase and convert the following words into lowercase. But it leaves other values unchanged. Within the following statements, we used the numeric values along with letters, and you can see the above String Method output for further reference.

Str4 = 'pyTHon 1234 tuTorIal'.capitalize()
print('Third Output after Capitalize() method is = ', Str4)

Str5 = '12345'.capitalize()
print('Fourth Output after Capitalize() method is = ', Str5)

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File Handling
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python numpy concatenate
  • Python numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python substring
  • Python Programming Examples

Copyright © 2021· All Rights Reserved.
About | Contact | Privacy Policy