Home  >  Article  >  Backend Development  >  Use of the isdecimal() method to process strings in Python

Use of the isdecimal() method to process strings in Python

高洛峰
高洛峰Original
2017-01-09 11:40:312208browse

The isdecimal() method checks whether a string consists of decimal characters only. This method only exists for unicode objects.

Note: To define a string as Unicode, just prefix it with a 'u' left quote. Below are examples.
Syntax

The following is the syntax of the isdecimal() method:

str.isdecimal()

##Parameters

NA

Return value

This method returns true if all characters in the string are decimal, otherwise it returns false.

Example

The following example shows the use of isdecimal() method.

#!/usr/bin/python
 
 
str = u"this2009";
print str.isdecimal();
 
str = u"23443434";
print str.isdecimal();

When we run the above program, it will produce the following results:

False
True

More isdecimal( ) method, please pay attention to the PHP Chinese website for related articles!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn