Check If Variable Is Dictionary In Python
Last updated June 21, 2023 by Jarvis Silva
In this tutorial we will see how to check if a variable is a 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 python program to check if variable is dictionary, in the code we used the type function which returns to us variable type so we checked using if statement if the variable type is dict then print it is a dictionary.
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 or use this online python compiler.
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.
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 🙂