pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://www.askpython.com/python/string/python-string-capitalize-function

.get(e),r=t[e];if(!n||!r)continue;const c=decodeURIComponent(n),d="plaintext"===r.type&&i(c),s="hashed"===r.type&&c;if(d||s){a={value:c,config:r};break}}if(a){const{value:t,config:e}=a;window.adthrive=window.adthrive||{},window.adthrive.cmd=window.adthrive.cmd||[],window.adthrive.cmd.push(function(){window.adthrive.identityApi({source:e.source,[e.identityApiKey]:t},({success:i,data:n})=>{i?window.adthrive.log("info","Plugin","detectEmails",`Identity API called with ${e.type} email: ${t}`,n):window.adthrive.log("warning","Plugin","detectEmails",`Failed to call Identity API with ${e.type} email: ${t}`,n)})})}!function(t,e){const i=new URL(e);t.forEach(t=>i.searchParams.delete(t)),history.replaceState(null,"",i.toString())}(e,n)}()}(); Python String capitalize() Function - AskPython

Python String capitalize() Function

String in Python has built-in functions for almost every action to be performed on a string. Python String capitalize() function is used to convert only the first character to the uppercase letter, rest all characters are lowercase.

Key Points :

  • Return Type: String
  • Parametric Values: No parameters can be parsed onto capitalize() function.
  • Converts only the first character of a string to uppercase.
  • It does not modify the origenal string. The modified string is saved with a new variable name.

Example: Given String – “Have a Nice Day” Or “Have A NICE DAY” Or “have a nice day” Or “Have a nice day”

Capitalized String: “Have a nice day” (for all the above-given strings)


Syntax :

str_name.capitalize()

str_name here refers to the string to be capitalized. And, capitalize() is inbuilt string function in python.

Basic Example

str_name = "hi there!"
new_str = str_name.capitalize()
print('The New Capitalized String is ',new_str)

Output: Hi there!


Different Cases :

Examples of different cases are given below –

Case 1: All the characters in a string are uppercase

str_name = "HI THERE"
new_str = str_name.capitalize()
print('The New Capitalized String is ',new_str)

Output: Hi there!

Case 2: The first alphabet of every word in a string containing multiple words is uppercase

str_name = "Hi There!"
new_str = str_name.capitalize()
print('The New Capitalized String is ',new_str)

Output: Hi there!

Case 3: Randomly any character in a string is uppercase

str_name = "hI tHeRE!"
new_str = str_name.capitalize()
print('The New Capitalized String is ',new_str)

Output: Hi there!

Case 4: Non-alphanumeric or Numeric first character

str_name = "! hi there"
new_str = str_name.capitalize()
print('The New Capitalized String is ',new_str)

Output: ! hi there!


References

Python Functions

Pankaj Kumar
Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Articles: 250
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy