Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
HowToDoInJava
  • Java
  • Spring AI
  • Spring Boot
  • Hibernate
  • JUnit 5
  • Interview

Python String capitalize()

In Python, the capitalize() method capitalizes a string i.e. upper case the very first letter in the given string and lowercases all other characters, if any. Except changing the case (upper/lower), capitalize() does not modify the content of the original string. 1. capitalize() Syntax The syntax of capitalize() …

Lokesh Gupta

July 8, 2021

Python String Functions
Python Basics
Python

In Python, the capitalize() method capitalizes a string i.e. upper case the very first letter in the given string and lowercases all other characters, if any.

Except changing the case (upper/lower), capitalize() does not modify the content of the original string.

1. capitalize() Syntax

The syntax of capitalize() is pretty simple.

string.capitalize()

2. capitalize() Example

Lets see few examples to understand the usage of capitalize() in Python.

Example 1: Capitalizing when first character is alphabet

string = "god is Great"

capitalizedString = string.capitalize()

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

Program output.

Old String:  god is Great
Capitalized String: God is great

Example 2: Capitalizing when first character is non-alphabet

Notice how the capital ‘N’ has been converted to small ‘n’. It concludes that even if first character is non-alphabet, capitalize() method still checks the whole string and make them lowercase.

string = "0 is most powerful Number"

capitalizedString = string.capitalize()

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

Program output.

Old String:  0 is most powerful Number
Capitalized String: 0 is most powerful number

Happy Learning !!

Comments

Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Python Built-in Functions

  • Python abs()
  • Python all()
  • Python any()
  • Python ascii()
  • Python bin()
  • Python input()
  • Python range()
  • Python print()

Python String Functions

  • String capitalize()
  • String count()
  • String endswith()
  • String split()
  • String startswith()

Table of Contents

  • 1. capitalize() Syntax
  • 2. capitalize() Example
      • Example 1: Capitalizing when first character is alphabet
      • Example 2: Capitalizing when first character is non-alphabet
Photo of author

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Follow on Twitter Portfolio

Previous

Spring Boot HikariCP DataSource Configuration

Next

Python String count()

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Tutorial Series

OOP

Regex

Maven

Logging

TypeScript

Python

Meta Links

About Us

Advertise

Contact Us

Privacy Policy

Our Blogs

REST API Tutorial

Follow On:

  • Github
  • LinkedIn
  • Twitter
  • Facebook
Copyright © 2026 | Sitemap