Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Python

Python String | isalnum() and isalpha() Methods with Examples



Python Strings | isalnum() and isalpha() Methods with Example, these are the in-built methods. Here, we will learn about isalnum() and isalpha() methods of Python String.
Submitted by IncludeHelp, on July 08, 2018

1 ) isalpha() Method

isalpha() method returns true if all characters of a string are only alphabets (between ‘A’ to ‘Z’ and between ‘a’ to ‘z’). If there is any non alphabet character in the string, method returns false.

Syntax:

    string.isalpha()

Parameter: None

Return type:

  • true - if all characters of the string are alphabets.
  • false - if any of the character of the string is not an alphabet (like number, space, special characters).

Example:

# str1 with only alphabets
str1 = "Helloworld"

# str2 with alphabets, space and special character
str2 = "Hello world!"

# str3 with alphabets, space and numbers
str3 = "Hello world 100"

# check whether string contains only alphabets or not
print str1.isalpha ()
print str2.isalpha ()
print str3.isalpha ()

Output

    True
    False
    False

2) isalnum() Method

isalnum() method returns true if all characters of a string are either alphabets (between ‘A’ to ‘Z’ and between ‘a’ to ‘z’) or numbers (0 to 9) or both, otherwise method returns false.

Syntax:

    string.isalnum()

Parameter: None

Return type:

  • true - if all characters of the string are alphabets or/and numbers.
  • false - if any of the character of the string is not either an alphabet or a number.

Example:

# str1 with alphabets and numbers
str1 = "Helloworld123"

# str2 with only alphabets
str2 = "Helloworld"

# str3 with numbers only
str3 = "12345"

# str4 with alpa numeric characters and space 
str4 = "Amit Shukla 21"

# check whether string contains only alphabets or not
print str1.isalnum ()
print str2.isalnum ()
print str3.isalnum ()
print str4.isalnum ()

Output

    True
    True
    True
    False





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.