I’m working through a Python 3 book and came across the string function isidentifier(). The text description is “s.isidentifier() : Returns True if s is non empty and is a valid identifier”. I tested it in the Python Shell like this:
>>> s = 'test'
>>> s.isidentifier()
True
>>> 'blah'.isidentifier()
True
I would expect the 2nd statement to return false since ‘blah’ is not held in a variable. Can anyone explain this? Thanks.
What they mean is that s could be valid as an identifier. It doesn’t imply that it is an identifier that’s in use.
Your first example is showing the same thing: ‘test’ (what
isidentifieris actually checking) is not the name of a variable either. I think you meant