{"id":10293,"date":"2021-03-27T10:10:39","date_gmt":"2021-03-27T04:40:39","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=10293"},"modified":"2023-04-30T13:27:21","modified_gmt":"2023-04-30T07:57:21","slug":"check-data-type-python","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/check-data-type-python\/","title":{"rendered":"How to Check Data Type in Python | Type() Function &#038; More"},"content":{"rendered":"\n<p>Python has many built-in functions. In this tutorial, we will be discussing how to check the data type of the variables in python by using type(). <strong>As while programming in Python, we came to a situation where we wanted to check the data-type of the variable we use type() function.<\/strong> This article will help you understand the concept of type() function.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#What_is_type_function\" >What is type() function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Syntax\" >Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Parameter\" >Parameter<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Syntax-2\" >Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Parameter-2\" >Parameter<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Return_value\" >Return value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Examples_to_Check_Data_Type_in_Python\" >Examples to Check Data Type in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#1_Using_typeobject_Method_to_Check_Data_Type_in_Python\" >1. Using type(object) Method to Check Data Type in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#2_Using_typename_bases_dict_method_to_Check_Data_Type_in_Python\" >2. Using type(name, bases, dict) method to Check Data Type in Python<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Difference_between_type_and_isinstance\" >Difference between type() and isinstance()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Type_Function\" >Type() Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Isinstance_Function\" >Isinstance() Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Example_of_type_and_isinstance_function\" >Example of type() and isinstance() function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Checking_Array_Data_Type_using_if_hasattrN_%E2%80%9C_len_%E2%80%9D\" >Checking Array Data Type (using if hasattr(N, &#8220;_len_&#8221;))<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Checking_for_datatype_of_variable_else_raise_error_Using_assert\" >Checking for datatype of variable, else raise error (Using assert)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Check_if_data_type_is_boolean_python\" >Check if data type is boolean python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Check_data_type_Python_Dataframe\" >Check data type Python Dataframe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#FAQs\" >FAQs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-type-function\"><span class=\"ez-toc-section\" id=\"What_is_type_function\"><\/span>What is type() function?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Python type() is a built-in function that helps you find the class type of the variable given as input.<\/strong> You have to just place the variable name inside the type() function, and python returns the datatype. <\/p>\n\n\n\n<p>Mostly, We use it for debugging purposes. we can also pass three arguments to type(), i.e., type(name, bases, dict). In such a case, it will return you a new type of object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-syntax\"><span class=\"ez-toc-section\" id=\"Syntax\"><\/span>Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>type(object)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameter\"><span class=\"ez-toc-section\" id=\"Parameter\"><\/span>Parameter<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The object argument is the required parameter to be passed inside the type() function. The argument can be string, integer, list, tuple, set, dictionary, float, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-syntax-1\"><span class=\"ez-toc-section\" id=\"Syntax-2\"><\/span>Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>type(name, bases, dict)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameter-1\"><span class=\"ez-toc-section\" id=\"Parameter-2\"><\/span>Parameter<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>name:<\/strong> It is the name of the class.<\/li>\n\n\n\n<li><strong>bases:<\/strong> It is the optional parameter, and it is the name of the base class.<\/li>\n\n\n\n<li><strong>dict:<\/strong> It is an optional parameter, and it is the namespace that has a definition of the class.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-return-value\"><span class=\"ez-toc-section\" id=\"Return_value\"><\/span>Return value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If we pass only the object as the parameter, it will only return the object&#8217;s type.<\/li>\n\n\n\n<li>If we pass the name, bases, and dict as the parameter, it will return the new type.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-examples-to-check-data-type-in-python\"><span class=\"ez-toc-section\" id=\"Examples_to_Check_Data_Type_in_Python\"><\/span>Examples to Check Data Type in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us discuss certain ways through which we can print the datatype of the variable. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-using-type-object-method-to-check-data-type-in-python\"><span class=\"ez-toc-section\" id=\"1_Using_typeobject_Method_to_Check_Data_Type_in_Python\"><\/span>1. Using type(object) Method to Check Data Type in Python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, we will be taking the input in all the forms to write the variable like string, integer, negative value, float value, complex number, list, tuple, set, and <a href=\"https:\/\/docs.python.org\/3\/c-api\/dict.html\" target=\"_blank\" rel=\"noreferrer noopener\">dictionary<\/a>. After that, we will print the data type of all the variables and see the output.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#taking input\n\nstr = 'Python pool'\nprint('Datatype : ',type(str))\n\nnum = 100\nprint('Datatype : ',type(num))\n\nneg = -20\nprint('Datatype : ',type(neg))\n\nfloat = 3.14\nprint('Datatype : ',type(float))\n\ncomplex = 2 + 3j\nprint('Datatype : ',type(complex))\n\nlst = &#x5B;1,2,3,4,5]\nprint('Datatype : ',type(lst))\n\nTuple = (1,2,3,4,5)\nprint('Datatype : ',type(Tuple))\n\nDict = {&quot;a&quot; : 2, &quot;b&quot; :3, &quot;c&quot; :1}\nprint('Datatype : ',type(Dict))\n\nset = {'a', 'b', 'c', 'd'}\nprint('Datatype : ',type(set))\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Datatype :  &lt;class 'str'&gt;\nDatatype :  &lt;class 'int'&gt;\nDatatype :  &lt;class 'int'&gt;\nDatatype :  &lt;class 'float'&gt;\nDatatype :  &lt;class 'complex'&gt;\nDatatype :  &lt;class 'list'&gt;\nDatatype :  &lt;class 'tuple'&gt;\nDatatype :  &lt;class 'dict'&gt;\nDatatype :  &lt;class 'set'&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>First, we declare the variables and then check the type using the type() function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-using-type-name-bases-dict-method-to-check-data-type-in-python\"><span class=\"ez-toc-section\" id=\"2_Using_typename_bases_dict_method_to_Check_Data_Type_in_Python\"><\/span>2. Using type(name, bases, dict) method to Check Data Type in Python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, we will be taking all the parameters like name, bases, and dict. after that, we will print the output. Let see more clearly with the help of the program.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Python:\n  x = 'python pool''\n  y = 100\n\nt1 = type('NewClass', (Python,), dict(x='Python pool', y=100))\nprint(type(t1))\nprint(vars(t1))\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;class 'type'&gt;\n{'x': 'Python pool', 'y': 100, '__module__': '__main__', '__doc__': None}<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Firstly, we have taken a class, Python.<\/li>\n\n\n\n<li>Then, we have taken a string and integer value inside the class python.<\/li>\n\n\n\n<li>Then, we have taken a variable as t1 in which we have applied the type() with the parameter as name, bases, and dict<\/li>\n\n\n\n<li>After that, we have printed the type of t1 and<a href=\"http:\/\/www.pythonpool.com\/python-vars\/\" target=\"_blank\" rel=\"noreferrer noopener\"> vars<\/a> of t1.<\/li>\n\n\n\n<li>At last, you can see the output.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-difference-between-type-and-isinstance\"><span class=\"ez-toc-section\" id=\"Difference_between_type_and_isinstance\"><\/span>Difference between type() and isinstance()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-type-function\"><span class=\"ez-toc-section\" id=\"Type_Function\"><\/span>Type() Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Python type() is a built-in function that helps you find the class type of the variable given as input.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-isinstance-function\"><span class=\"ez-toc-section\" id=\"Isinstance_Function\"><\/span>Isinstance() Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Python isinstance() function is used to check if the object (first argument) is an instance or subclass of classinfo class (second argument).<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-of-type-and-isinstance-function\"><span class=\"ez-toc-section\" id=\"Example_of_type_and_isinstance_function\"><\/span>Example of type() and isinstance() function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In this example, we will be discussing about both the functions and explained in detail.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nage = 100\nprint(&quot;Datatype : &quot;,type(age))\n\nage = isinstance(100,int)\nprint(&quot;age is an integer:&quot;, age)\n<\/pre><\/div>\n\n\n<p class=\"has-medium-font-size\"><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Datatype :  &lt;class 'int'&gt;\nage is an integer: True<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Firstly, we have taken age as a variable with a value equal to 100.<\/li>\n\n\n\n<li>Then, we have printed the datatype of the age value.<\/li>\n\n\n\n<li>After that, we have applied<code> isinstance()<\/code> function with two parameters as the value of age and type of age.<\/li>\n\n\n\n<li>At last, we have printed the output.<\/li>\n\n\n\n<li>By seeing the output, we can see the difference between the type and <code>isinstance<\/code> function.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Checking_Array_Data_Type_using_if_hasattrN_%E2%80%9C_len_%E2%80%9D\"><\/span>Checking Array Data Type (using if hasattr(N, &#8220;_len_&#8221;))<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can check the array data type using hasattr() function in python by specifying the function. For this you need to know the functions of the array. Here, __len__ provides the length of the data which you have passed. So if hasattr can determine a function that belongs to the array, we can call it array data type. Here, the function which we&#8217;ll use is __len__.<\/p>\n\n\n\n<p>For example,<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\narr=&#x5B;1,2,3]\nif hasattr(arr, '__len__'):\n\u00a0\u00a0\u00a0\u00a0print('array found')\nelse:\n\u00a0\u00a0\u00a0\u00a0print('not found')\n\n#array found (Output)\n<\/pre><\/div>\n\n\n<p>Here, the __len__ function determined the length of the arr that was passed as an argument. This function belongs to array data type so we used &#8216;if&#8217; to see if this attribute is present in array.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Checking_for_datatype_of_variable_else_raise_error_Using_assert\"><\/span>Checking for datatype of variable, else raise error (Using assert)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The syntax of assert is :&nbsp;<\/p>\n\n\n\n<p><em>assert condition, message<\/em><\/p>\n\n\n\n<p>It is used just like &#8216;raise&#8217; to throw an exception but here, a condition is also specified.&nbsp;<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nx = 'abc'\nprint(type(x))\n\nassert type(x) != int, 'x is an integer'\n\nprint('x is not an integer')\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_if_data_type_is_boolean_python\"><\/span>Check if data type is boolean python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can assess whether the given data belongs to boolean or not. In this case, you will put either True or False as the input to get a boolean type.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\na = True\ntype(a)\n\n#class&amp;lt;bool&gt;\n<\/pre><\/div>\n\n\n<p>The type function is an easy-to-use tool to find the data type in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_data_type_Python_Dataframe\"><\/span>Check data type Python Dataframe<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To find the data type for a dataframe in python, you may use the dtype function.&nbsp;<\/p>\n\n\n\n<p>For example,&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport pandas as pd\ndf = pd.DataFrame({'A':&#x5B;10,11], 'C':&#x5B;1.3, 0.23]})\n\nprint(&quot;DataFrame:&quot;)\n\nprint(df)\n\nresult = df.dtypes\n\nprint(&quot;Output:&quot;)\n\nprint(result)\n\n#Make sure that all the columns have the same size\n<\/pre><\/div>\n\n\n<p>And you will obtain the given output\u00a0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DataFrame:\n\n\u00a0\u00a0\u00a0\u00a0A \u00a0 \u00a0 C\n\n0\u00a0 10\u00a0 1.30\n\n1\u00a0 11\u00a0 0.23\n\nOutput:\n\nA\u00a0 \u00a0 \u00a0 int64\n\nC\u00a0 \u00a0 float64\n\ndtype: object<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1682838594993\"><strong class=\"schema-faq-question\">What is Dtype in Python pandas?<\/strong> <p class=\"schema-faq-answer\">It is a function that helps to find out the data type of the attributes of a dataframe object in python.\u00a0<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1682840200104\"><strong class=\"schema-faq-question\">How do you check if datatype is a number Python?<\/strong> <p class=\"schema-faq-answer\">We can check it using the type function.\u00a0<br\/>var = 4 if type(var)==int: \u00a0\u00a0\u00a0\u00a0print(&#8220;Numeric&#8221;) else: \u00a0\u00a0\u00a0\u00a0print(&#8220;Not numeric&#8221;)<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this tutorial, we have learned how to check the variable&#8217;s data type by using type() with two different parameters. We have also explained all the variables using type() with examples explained in detail.<\/p>\n\n\n\n<p>However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python has many built-in functions. In this tutorial, we will be discussing how to check the data type of the variables in python by using &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to Check Data Type in Python | Type() Function &#038; More\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/#more-10293\" aria-label=\"More on How to Check Data Type in Python | Type() Function &#038; More\">Read more<\/a><\/p>\n","protected":false},"author":17,"featured_media":10308,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[3788,3787,3786],"class_list":["post-10293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-check-data-type-python","tag-python-data-type-check","tag-python-type-function","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Check Data Type in Python | Type() Function &amp; More - Python Pool<\/title>\n<meta name=\"description\" content=\"Python type() is a built-in function that helps you to check the data type of the variable given as input. It has two different parameters.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/check-data-type-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Check Data Type in Python | Type() Function &amp; More\" \/>\n<meta property=\"og:description\" content=\"Python has many built-in functions. In this tutorial, we will be discussing how to check the data type of the variables in python by using type(). As\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/check-data-type-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-27T04:40:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-30T07:57:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Siddharth Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/\"},\"author\":{\"name\":\"Siddharth Jain\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\"},\"headline\":\"How to Check Data Type in Python | Type() Function &#038; More\",\"datePublished\":\"2021-03-27T04:40:39+00:00\",\"dateModified\":\"2023-04-30T07:57:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/\"},\"wordCount\":944,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png\",\"keywords\":[\"check data type python\",\"python data type check\",\"python type function\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/check-data-type-python\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/\",\"url\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/\",\"name\":\"How to Check Data Type in Python | Type() Function & More - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png\",\"datePublished\":\"2021-03-27T04:40:39+00:00\",\"dateModified\":\"2023-04-30T07:57:21+00:00\",\"description\":\"Python type() is a built-in function that helps you to check the data type of the variable given as input. It has two different parameters.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993\"},{\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/check-data-type-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png\",\"width\":1350,\"height\":650,\"caption\":\"check data type python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Check Data Type in Python | Type() Function &#038; More\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\",\"name\":\"Siddharth Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"caption\":\"Siddharth Jain\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993\",\"name\":\"What is Dtype in Python pandas?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"It is a function that helps to find out the data type of the attributes of a dataframe object in python.\u00a0\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104\",\"name\":\"How do you check if datatype is a number Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"We can check it using the type function.\u00a0<br\/>var = 4 if type(var)==int: \u00a0\u00a0\u00a0\u00a0print(\\\"Numeric\\\") else: \u00a0\u00a0\u00a0\u00a0print(\\\"Not numeric\\\")\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Check Data Type in Python | Type() Function & More - Python Pool","description":"Python type() is a built-in function that helps you to check the data type of the variable given as input. It has two different parameters.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/check-data-type-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Check Data Type in Python | Type() Function & More","og_description":"Python has many built-in functions. In this tutorial, we will be discussing how to check the data type of the variables in python by using type(). As","og_url":"https:\/\/www.pythonpool.com\/check-data-type-python\/","og_site_name":"Python Pool","article_published_time":"2021-03-27T04:40:39+00:00","article_modified_time":"2023-04-30T07:57:21+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png","type":"image\/png"}],"author":"Siddharth Jain","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Siddharth Jain","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/"},"author":{"name":"Siddharth Jain","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa"},"headline":"How to Check Data Type in Python | Type() Function &#038; More","datePublished":"2021-03-27T04:40:39+00:00","dateModified":"2023-04-30T07:57:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/"},"wordCount":944,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png","keywords":["check data type python","python data type check","python type function"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/check-data-type-python\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/","url":"https:\/\/www.pythonpool.com\/check-data-type-python\/","name":"How to Check Data Type in Python | Type() Function & More - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png","datePublished":"2021-03-27T04:40:39+00:00","dateModified":"2023-04-30T07:57:21+00:00","description":"Python type() is a built-in function that helps you to check the data type of the variable given as input. It has two different parameters.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993"},{"@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/check-data-type-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/How-to-check-Datatype-in-Python.png","width":1350,"height":650,"caption":"check data type python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"How to Check Data Type in Python | Type() Function &#038; More"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa","name":"Siddharth Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","caption":"Siddharth Jain"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993","position":1,"url":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682838594993","name":"What is Dtype in Python pandas?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"It is a function that helps to find out the data type of the attributes of a dataframe object in python.\u00a0","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104","position":2,"url":"https:\/\/www.pythonpool.com\/check-data-type-python\/#faq-question-1682840200104","name":"How do you check if datatype is a number Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"We can check it using the type function.\u00a0<br\/>var = 4 if type(var)==int: \u00a0\u00a0\u00a0\u00a0print(\"Numeric\") else: \u00a0\u00a0\u00a0\u00a0print(\"Not numeric\")","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=10293"}],"version-history":[{"count":17,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10293\/revisions"}],"predecessor-version":[{"id":27408,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/10293\/revisions\/27408"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/10308"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=10293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=10293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=10293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}