This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
You can check if a variable is a string using the type()
function, passing the variable as an argument, and then comparing the result to the str
class:
name = "Roger"
type(name) == str #True
Or using isinstance()
, passing 2 arguments: the variable, and the str
class:
name = "Roger"
isinstance(name, str) #True
This content originally appeared on flaviocopes.com and was authored by flaviocopes.com
flaviocopes.com | Sciencx (2021-03-01T05:00:00+00:00) How to check if a variable is a string in Python. Retrieved from https://www.scien.cx/2021/03/01/how-to-check-if-a-variable-is-a-string-in-python/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.