×

Python String isalpha() method

Python String isalpha() method

The string.isalpha () method in Python returns a boolean value true if all characters in the  string are alphabetic else for any other value it returns false.

Syntax

isalpha() 

Parameter

NA

Return

This method returns a boolean value true if all characters in the string are alphabetic.

Example 1

 # Python programing explaining
 # the isalpha() method
 # initializing a alhabetic value 
 strVal = "JulyApril"; 
 # returning a boolean value if all the string characters are alphabetic
 bool= strVal.isalpha()
 # prinitng the boolean value
 print("The'",strVal,"' contains all alphabetic value:",bool) 

Output

The' JulyApril ' contains all alphabetic value: True

Example 2

 # Python programing explaining
 # the isalpha() method
 # initializing a string value
 strVal = "Hello"
 # validating if and else condition
 if strVal.isalpha() == True:
    print("All the characters of the specified string are alphabtes.")
 else:
     print("All the characters are not alphabtes.") 

Output

All the characters of the specified string are alphabtes.

Example 3

 # Python programing explaining
 # the isalpha() method
 # initializing a string value
 char1 = "HelloWorld" # will return true as the string is alphabetic
 print(char1.isalpha())
 # string containing whitespace
 char2 = "Hello World " # will return False as the string contains whitespace
 print(char2.isalpha())
 #passing special characters 
 char3 = "!Mo3nica*$Gell22er" # will return false as it contains special characters
 print(char3.isalpha())
 # passing alphanumeric 
 char4 = "hello133world"# will return False as it is alphanumeric
 print(char4.isalpha()) 

Output

 True
 False
 False
 False 

Related Topics

How to Write a Configuration file in Python

This article will discuss How to write a configuration file in python, why we need config files in Python, the format of the configuration file, file extensions, and how to...

11 minutes read.

Python Logistic Regression with Sklearn & Scikit

In this article, we'll walk through a tutorial for utilising the Python Sklearn (formerly known as Scikit Learn) package to implement logistic regression. To assist you in remembering the concept,...

18 minutes read.

Python Bitwise Operators

When used with variables and objects in an expression, operators are tokens that carry out calculations. The variables and items to which the computation is applied are known as operands....

5 minutes read.

Python bin() function

Python bin() function The bin() function in Python returns the binary version for the specified integer. Syntax bin(x) Parameter n: This parameter represents an integer or int value. Return This function returns a binary string for the specified integer...

1 minute read.

Scraping data in python

Data scraping is a technique in which one program extracts a set of data from the output of another program. Web scraping is the most common application of this technique....

6 minutes read.

Inheritance in Python

Inheritance in Python Object-Oriented Programming provides reusable patterns to the code for restricting the redundancy in development projects. One of the basic principles of Object-Oriented Programming that helps achieve recyclable code...

8 minutes read.

List Comprehension in Python3

List A list in python is a complex data type, and a list is a collection of the number of data. The data variable may or may not be of the...

5 minutes read.

Python hash() function

Python hash() function The hash() function in Python returns the hash value of the object (if it has one).  Syntax hash(object) Parameter obj : This parameter represents the object which we need to convert into hash. Return This...

1 minute read.

Check Palindrome in Python

Python is an object-oriented high-level programming language. Python has dynamic semantics and has high-level built-in data structures which support dynamic typing and dynamic binding. Python provides rapid development. It has...

4 minutes read.

How to check the version of the Python Interpreter?

As we all know what an interpreter is, and how important it is. We should also be aware of the fact that it is important to have knowledge of the...

2 minutes read.

What does base case mean in recursion

Base cases and recursive stages are used to define recursive functions. In a primary subject, we compute the outcome right away, given the function call's arguments. In a recursive step, we...

4 minutes read.

Global variables in python

In Python, considering the scope, variables are categorized into global and local variables. In this article, we will discuss these two types along with examples. Any variable holds a value in...

4 minutes read.

What is Python online compiler?

The compiler is a program that is used to scan an entire high-level program (source code) and it translates the scanned program into machine code. Compilers convert .py source code into...

5 minutes read.

How to handle exceptions in python

Prerequisite: Exceptions and errors in Python What are Exceptions? Exceptions are run-time errors that unexpectedly occur and crash a program. When occurred, it alters the flow of the program. These errors are...

9 minutes read.

Difference between Package and Module in Python

What are Python modules? A file with the “.py” suffix that includes Python or C executable code is known as a module. Multiple Python commands and expressions make compose a module....

3 minutes read.

Python String strip() method

Python String strip() method The string. strip() method in Python removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to...

1 minute read.

To Do GUI Application using Tkinter in Python

GUI: One of the most significant factors that increased the usability of computer and digital technologies for common, less tech-savvy users is likely the development and widespread adoption of GUIs. GUIs...

3 minutes read.

Index Error in Python

The index errors are the run time error that is raised in Python when we try to access an index that does not exist. This might seem very trivial but...

4 minutes read.

Python next() function

Python next() function The next() function in Python retrieves the next item from the iterator.  Syntax next(iterator[, default]) Parameter iterable: It is a required parameter which represents an iterable object. default: This parameter represents a default value to...

1 minute read.

Python Program to find the length of a string

Python program to find the length of a string A string in Python is a set of Unicode characters. It can't be changed once it's been declared. The number of characters...

2 minutes read.