{"id":13931,"date":"2022-01-17T09:08:06","date_gmt":"2022-01-17T09:08:06","guid":{"rendered":"https:\/\/linuxways.net\/?p=13931"},"modified":"2022-01-17T09:08:06","modified_gmt":"2022-01-17T09:08:06","slug":"python-isinstance-function","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/python-isinstance-function\/","title":{"rendered":"Python isinstance() Function"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The isinstance() function in Python allows checking if an object is of the specified type. In other words, it will check if the 1st parameter is a subclass of the 2nd parameter.<\/p>\n<p>If it matches it will return True, otherwise, it will return False.<\/p>\n<p>Now we&#8217;re gonna teach you to use the isinstance() function in Python.<\/p>\n<h2>Example<\/h2>\n<p><strong>Example 1<\/strong>:<\/p>\n<pre>x = isinstance(1, int)\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>True<\/strong><\/p>\n<p><strong>Example 2<\/strong>:<\/p>\n<pre>x = isinstance(1, float)\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>False<\/strong><\/p>\n<h2>Definition<\/h2>\n<p>If an object is of the specified type, this function will return <strong>True<\/strong>, otherwise, it will return <strong>False<\/strong>.<\/p>\n<p>The case the parameter is of type tuple, if the object is one of type tuple, it will return <strong>True<\/strong>.<\/p>\n<h2>The syntax<\/h2>\n<pre>isinstance(object, type)<\/pre>\n<p><strong>Parameter Values<\/strong>:<\/p>\n<p>object: an object(Required)<\/p>\n<p>type: class, type or tuple<\/p>\n<h2>More examples<\/h2>\n<p><strong>Example 1<\/strong>:<\/p>\n<pre>class NAME:\r\n\r\nname = \"BEND\"\r\n\r\nz = NAME()\r\n\r\nx = isinstance(z, NAME)\r\n\r\nprint(x)<\/pre>\n<p>Output:<\/p>\n<p><strong>True<\/strong><\/p>\n<p><strong>Example 2<\/strong>:<\/p>\n<pre>testlist = [1, 2, 3]\r\n\r\nprint(isinstance(testlist, list))<\/pre>\n<p>Output:<\/p>\n<p><strong>True<\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>We just taught you to use the isinstance() function in Python.<\/p>\n<p>Thank you for referring!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The isinstance() function in Python allows checking if an object is of the specified type. In other words, it will check if the 1st parameter is a&hellip;<\/p>","protected":false},"author":1,"featured_media":14007,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[849,10],"class_list":["post-13931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-isinstance","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/13931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=13931"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/13931\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14007"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=13931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=13931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=13931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}