Use the isinstance built-in function to check if the variable is a string in Python. It takes two arguments, the first is variable, and the second is the type you want to check for.
Python checks if the variable is a string example
Simple example code, The first parameter will be given a variable, and the second is the data type string.
var = "String" print(isinstance(var, str))
Uses the type built-in function to see if the type of your variable is str.
var = "String" if type(var) == str: print("String type")
Output: String type
Do comment if you have any questions or suggestions on this Python var string topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.