For more information about the Python isalnum string method visit our site at
http://learnpythontutorial.com/python...
Python Isalnum String Method
In this Python tutorial we take a look at the Python isalnum string method in Python. The isalnum string method allow us to check if all the contents of a string are numbers. This string method only works with integers not floating point numbers because floating point numbers contain decimals. If the string object contains all numbers and no other characters we will be returned a boolean of True. If the string object contains anything other than an integer we be returned a boolean of False.
Python Isalnum String Method Syntax
'String'.isalnum()
'String' - The string must contain only numbers(integers) for a True return and if the string object contains anything other a number then we will get a False statement.
Examples Of The Python Isalnum String Method
Example 1:
'1243'.isalnum()
True
Example 2:
'4.5'.isalnum()
False
Example 3:
a = '56'
a.isalnum()
True
Example 4:
b = ' 98'
b.isalnum()
False
Examples Explained
Example 1:
'1243'.isalnum() - We create a string object that contains numbers and call the isalnum string method on our string object.
True- We are returned the boolean of True which means all characters contained in the string object are numbers.
Example 2:
'4.5'.isalnum() - We create a string object that contains numbers but this string object also contains a decimal point and then we call the isalnum string method on the string object.
False- We are returned False because our string object contains a decimal.
Example 3:
a = '56'- Here we create a new string object and assign a variable of 'a' to represent our string object. Our string object contains all numbers.
a.isalnum()- We call our string object via the variable of 'a' and then we call the isalnum string method on your string object.
True- We are returned True because our string object contains all numbers.
Example 4:
b = ' 98'- In this example, we create a string object that contains a space and some numbers. We chose the variable 'b' to represent the string object.
b.isalnum()- We call our string object via the variable of 'b' and then we call the isalnum string method on our object.
False - We are returned False because our string object contains a space.
Conclusion
In this Python tutorial we took a look at the Python isalnum string method. If you have any questions about this string method leave a comment below.
Python Tutorial: How To Use The Python Isalnum String Method | |
| 2,069 views views | 12,868 followers |
| 21 Likes | 21 Dislikes |
| Education | Upload TimePublished on 25 Sep 2015 |
Không có nhận xét nào:
Đăng nhận xét