Python inbuilt String Functions

capitalize()

The capitalize() method returns a string where the first character is upper case.

Syntax
string.capitalize()

n=”HELLO HOW ARE YOU”
print(n.capitalize())

Output:
Hello how are you

n=”hello world”
print(n.capitalize())

Output:
Hello world

n=”123hello”
print(n.capitalize())

output:
123hello

isalpha()

The isalpha() method returns True if all the characters are alphabet letters (a-z).
Example of characters that are not alphabet letters: (space)!#%&? etc.

Syntax
string.isalpha()

Check if all the characters in the text are alphabets

n=”Hello”
print(n.isalpha())

Output:
True

n=”hello9″
print(n.isalpha())

Output:
False

n=”7Hello”
print(n.isalpha())

Output:
False

n="Hello"
print(n.isalpha())

n="hello9"
print(n.isalpha())

n="7Hello"
print(n.isalpha())

Output:

True
False
False

islower()

The islower() method returns True if all the characters are in lower case, otherwise False.
Numbers, symbols and spaces are not checked, only alphabet characters.

Syntax
string.islower()

Example
Check if all the characters in the text are in lower case:

n=”computer”
print(n.islower())

Output:
True

n=”Computer”
print(n.islower())

Output:
False

n=”COMPUTER”
print(n.islower())

Output:
False

n=”computer123″
print(n.islower())

Output:
True

n="computer"
print(n.islower())

n="Computer"
print(n.islower())

n="COMPUTER"
print(n.islower())

n="computer123"
print(n.islower())

Output:

True
False
False
True

Python String inbuilt Methods       Python Math inbuilt Methods       Python Date And Time inbuilt Methods      Python Random inbuilt Methods

Visitor Counter

0056704