Check If Variable Is Dictionary In Python

Want to know how to check if variable is dictionary in python, then you are at the right place today in this tutorial. I will show you how to check if a variable is dictionary in python, So follow this tutorial till the end.
To create this program we will use the type function to check whether a variable is a dictionary it is very simple program so let’s see it in code.
Program To Check If Variable Is Dictionary In Python
test = {'name':'Jason', 'Role':'Programmer'}
if type(test) is dict:
print("It is a dictionary")
else:
print("Not a dictionary")
Above is the program to check if variable is dictionary in python. Now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer.
To run this python program, follow the below steps:
- Create a new folder for this python project.
- Open it in a code editor of your choice.
- Create a python file with an ending .py extension.
- Copy the above code and paste it in your file.
- Open a terminal or CMD at folder location
- And type this command python filename.py (Name of your file).
After running this program you will see that it printed that it is a dictionary if you gave it any other variable then it will print not a dictionary.
As you can see we successfully created this program in python. Don’t want to create all the files and folders then you can run this program now using this online python compiler.
Summary
This was a simple program to check whether a variable is a dictionary in python. I hope you found this tutorial helpful and useful. Do share this tutorial with your friends who might need this program.
Here are some more python program tutorials for you:
- Python Program To Check If A Variable Is A Function.
- Python Program To Check Even Or Odd Numbers.
- Python Program To Check Composite Numbers.
- Python Program To Check Whether A Person Is Senior Citizen Or Not.
- Python Program To Check Whether A Person Is Eligible To Vote Or Not.
I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂