• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Python to Check if String Contains Only Letters

Using Python to Check if String Contains Only Letters

July 25, 2022 Leave a Comment

To check if a string only contains letters in Python, you can use the string isalpha() function.

a = "hello1"
b = "bye"
c = "123"

print(a.isalpha())
print(b.isalpha())
print(c.isalpha())

#Output:
False
True
False

When working with strings in Python, the ability to check these strings for certain conditions is very valuable.

One such case is if you want to check if a string variable contains only letters or not.

To check if a string variable only contains letters, we can use the string isalpha() function.

isalpha() returns True if all characters of the string are letters.

Below is an example showing you how to check if a string is made up of all letters in Python with isalpha().

a = "hello1"
b = "bye"
c = "123"

print(a.isalpha())
print(b.isalpha())
print(c.isalpha())

#Output:
False
True
False

Hopefully this article has been useful for you to check if a string only contains letters.

Other Articles You'll Also Like:

  • 1.  Check if Word is Palindrome Using Recursion with Python
  • 2.  Get Day of Year from Date in pandas DataFrame
  • 3.  pandas sum – Get Sum of Series or DataFrame Columns
  • 4.  Generate Random Float Between 0 and 1 Using Python
  • 5.  Check if Variable is Datetime in Python
  • 6.  Remove Element from Set in Python
  • 7.  Using Python to Create Empty DataFrame with pandas
  • 8.  pandas str replace – Replace Text in Dataframe with Regex Patterns
  • 9.  pandas mad – Calculate Mean Absolute Deviation in Python
  • 10.  Using Python to Split String by Tab

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy