Capitalize a string in Python: Convert the first letter to uppercase and other letters to lowercase
The capitalize()
converts a word to the "capitalized" word; the first letter is uppercase and other letters lowercase.
a = 'this iS an aPPle.'
b = a.capitalize()
print(b) # This is an apple.
Python Examples
print('3 Books weRE solD'.capitalize())
# 3 books were sold
print('"hello", he said.')
# "hello", he said.
print(' go '.capitalize())
# go
Numbers, symbols and spaces remain the same after capitalized.
Python String
- Check if a string contains the other string
- Check if a string starts with another string
- Split a string
- Concatenate strings
- Get the index of substring
- Get the index of the last occurrence of a substring
- Trim a string
- Replace a substring
- Replace multiple spaces with one space
- Fill 0 letters to a string
- Capitalize a string
- Convert a string lowercase
- Check if a string is numeric
- Check if a string is uppercase
- Parse a string to a float
- Format a string
- f-string
- Reverse a string
- Slice a string
- Subtract a string from another string
- Make a random string
- Generate a secure token
- Encode a string
- Get the sha256 value
- Convert an integer to a hexadecimal string
- Get a character or integer value
- Get digits or ASCII letters
- Center a string
- Convert string to tuple