• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 25, 2022 |1.3K Views

Python Program to Check if a Variable is String

  Share   Like
Description
Discussion

In this video, we will write a python program to check if a variable is a string. 

Below is the list of approaches that we will cover in this section: 

1. Using isinstance() 
3. Using type()

In this video, we will try to understand how the program distinguishes if the given variable is a string datatype or an integer and for that python has two inbuild methods which are isinstance() and type() method, which returns a boolean or object datatype.

Integer.isinstance() method can be used to test whether any variable is a particular datatype. By giving the second argument as “str”, we can check if the variable we pass is a string or not whereas, type() method returns class type of the argument(object) passed as parameter. 

The type() function is mostly used for debugging purposes.

Python | Check if a variable is string
https://www.geeksforgeeks.org/python-check-if-a-variable-is-string/