python text Determine if a class string is inside an object
Scene:
Determine if a class string is inside an object
usually immediately think of using type () to achieve
>>> def isexactlyastring(obj):
returntype (obj) isType ("')
>>> isexactlyastring (1)
False
>>> isexactlyastring (' 1 ')
True
>>>
And also
>>>def isastring(obj):
Try: obj+"'
except:return False
Else:return True
>>> isastring (1)
False
>>> isastring (' 1 ')
True
>>> isastring ({1})
False
>>> isastring ([' 1 '])
False
>>>
Although the use of ideas and methods are useless, but if the python features, we can find a better way to: isinstance (OBJ,STR)
>>> def isastring(obj):
returnIsinstance (OBJ,STR)
>>> isastring (1)
False
>>> isastring (' 1 ')
True
>>>
Stras aPython3inside the only String class, we can detect if the string isStrinstances of
Python text determines if a class string is inside the object