Python: is isalnum() the same as isalpha with isdigit?

2024/11/8 11:10:13

Is there a way to concretely verify this? I tried to solve a coding question but it seems one of the test cases (not revealed to me) takes this as wrong. In what kinds of cases does this fail to be true?

Answer

There are cases when both isalpha and isdigit returns False, but isalnum returns True. So isalnum is not just a combination of the other two.

>>> 'a1'.isalpha(), 'a1'.isdigit(), 'a1'.isalnum()
(False, False, True)
https://en.xdnf.cn/q/120623.html

Related Q&A

Python code works fine first time, but fails second time

The first time I run this block of code from Notebook it works fine:#Which letters and how many letters = ["a","b","c"] noOfLetters = len(letters)#Looking for all permutat…

How do I subtract a value in the dictionary? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

CSV IO python: converting a csv file into a list of lists

How to convert a csv file into a list of lists where each line is a list of entries with in a bigger list?Im having trouble with this because some of my entries have a comma in thema file like: 1,2,3…

Sheet of paper in millimeters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

Kivy App build with Buildozer. APK crash

I am using Oracle VirtualBox running Ubuntu 16. I have been able to build apk files for a while until my latest build. My program will run and keep its functionality when run with python 2.7 on the sam…

Python3 - convert csv to json using pandas

Ive got a .csv files with 5 columns but I only need the json file to contain 3 of these how would i go about doing it?csv file:Ncode Ocode name a b c 1 1.1 1x 1a 1b 1…

Python List of Dictionaries by Loops

I have 2 python list of dictionaries:[{index:1,color:red},{index:2,color:blue},{index:3,color:green} ]and[{device:1,name:x},{device:2,name:y},{device:3,name:z} ]How can I append each dictionary from th…

Removing parentheses and comma

Im importing Data from a database into python data frame. Now, I wish to use the data for further analysis, however, I need to do a little cleaning of the data before using. Currently, the required col…

Explicit Exception problem with try function

I have to run codes irrespective whether it fails or not. Im using ExplicitException. Following is my code:try:G.add_edge(data1[0][0],data1[1][0],weight=data1[2+i][0]) except ExplicitException:passtry:…

How do I perform a bubble sort in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 4 years ago.Improve…