×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python String capitalize() Method

By IncludeHelp Last updated : December 15, 2024

Python String capitalize() Method

The capitalize() is an in-built method in Python, it returns the string in Capitalized case, in which first character of the sentence is in uppercase and rest of the characters are in lowercase.

Syntax

 String.capitalize()

Parameters

None

Return Value

It returns capitalize case string.

Example 1

# str1
str1 = "Hello world, how are you?"
print(str1.capitalize())

# str2
str2 = "HELLO WORLD, HOW ARE YOU?"
print(str2.capitalize())

# str3
str3 = "hello world, how are you?"
print(str3.capitalize())

# str4
str4 = "100google is a website"
print(str4.capitalize())

Output

Hello world, how are you?
Hello world, how are you?
Hello world, how are you?
100google is a website

Example 2

str1 = "this is a test"
print(str1.capitalize())

str2 = "TESTING THE CAPITALIZE METHOD"
print(str2.capitalize())

str3 = "python programming"
print(str3.capitalize())

str4 = "123abc is a code"
print(str4.capitalize())

Output

This is a test
Testing the capitalize method
Python programming
123abc is a code

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.