Program for Python String isalpha() Method

In the previous article, we have discussed Python Program for isalnum() Function
isalpha() Function in Python:

If all of the characters are alphabet letters, the isalpha() method returns True (a-z).

(space)!#%&? etc are examples of characters that are not alphabets.

Syntax:

string.isalpha()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "pythonprograms"
Given second string = "123456good morning"

Output:

The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Example2:

Input:

Given first string = "hello123this is python programming platform"
Given second string = "hellogoodmorning"

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Program for isalpha() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello123this is python programming platform"
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "hellogoodmorning"
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

Enter some Random String = pythonprograms
The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
Enter some Random String = 123456good morning
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.