How to check if a variable is of a given type in Python?

How to check if a variable is of a given type in Python?

                                
                                  

# How to check if a variable is of a given type in Python? # Set username to string value. username = 'factober' # Check if username is of type int. # It should return False. result = isinstance(username, int) # Print result on terminal. print(result) # Check if username is of type string. # It should return True. result = isinstance(username, str) # Print result on terminal. print(result) # Set pincode to integer value. pincode = 1234 # Check if pincode is of type int. # It should return True. result = isinstance(pincode, int) # Print result on terminal. print(result) # Check if pincode is of type string. # It should return False. result = isinstance(pincode, str) # Print result on terminal. print(result)

Programming Language: Python
Description: Python is an interpreted high-level general-purpose programming language. It focuses on code readability with its indentation. It can be used for Automation, IoT, Game Development, Desktop Applications, Web Development, Artificial Intelligence, Machine Learning & Data Science.