Python 2
Use isinstance(obj, basestring) for an object-to-test obj.
Docs.
Answer from John Fouhy on Stack OverflowPython 2
Use isinstance(obj, basestring) for an object-to-test obj.
Docs.
Python 3
In Python 3.x basestring is not available anymore, as str is the sole string type (with the semantics of Python 2.x's unicode).
So the check in Python 3.x is just:
isinstance(obj_to_test, str)
This follows the fix of the official 2to3 conversion tool: converting basestring to str.
Videos
Is there some easy, built-in way to check if a given string contains at least one single digit, 0-9? Everything I'm searching talks about the in operator or the find method, but those seem to require that you already know which digit you are looking for.
I'm leaning toward using an RE, but I wanted to know if there was a simpler way first.
Examples that would evaluate to true would be:
'44 a b' 'aa ba 5' '45 187'
and false would be any string without at least one digit.
I figure I can just try to match it with \d+, but I don't want to rely on REs too much, even though I find them fun!
Thanks!
Basically the title, is there any way to check if a string wiuld be able to be converted to a float without causing an error? Have a python program that involves inserting a lot of numbers in sucession and I would like to not have to start again every time I accidentally make a typo
I'm really new to python and i'm having some trouble figuring out how to check if a list contains a certain character.
For example:
list = ['a1', 'a2', 'b1', 'b2', 'a3', 'a5', 'c3']
how would I check to see what elements contain the string 'a'? sorry if i didn't word my question properly i'm still very new to coding, but any help would be appreciated.