<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4719,"date":"2022-08-16T11:55:14","date_gmt":"2022-08-16T11:55:14","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4719"},"modified":"2022-08-16T11:55:14","modified_gmt":"2022-08-16T11:55:14","slug":"what-is-type-conversion-in-python","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/","title":{"rendered":"What is type conversion in python ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.<\/li>\n<li style=\"text-align: justify;\">The types conversion consists of two types, they are implicit conversion and explicit conversion.<\/li>\n<\/ul>\n<h2 id=\"implicit-conversion\" style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4720\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png\" alt=\"\" width=\"727\" height=\"412\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png 727w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion-300x170.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion-390x221.png 390w\" sizes=\"(max-width: 727px) 100vw, 727px\" \/>\u00a0<strong>Implicit Conversion<\/strong><\/h2>\n<ul style=\"text-align: justify;\">\n<li>In python implicit type conversion data types automatically converts one data type to another without any user involvement.<\/li>\n<\/ul>\n<h3 id=\"sample-code\" style=\"text-align: justify;\"><strong>Sample Code<\/strong><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-python code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-python code-embed-code\">x = 10\u00a0<br\/><br\/>print(&quot;x is of type:&quot;,type(x))\u00a0\u00a0<br\/><br\/>y = 10.6<br\/><br\/>print(&quot;y is of type:&quot;,type(y))<br\/><br\/>x = x + y<br\/><br\/>print(x)<br\/><br\/>print(&quot;x is of type:&quot;,type(x))<\/code><\/pre> <\/div>\n<h3 id=\"output\" style=\"text-align: justify;\">Output<\/h3>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4721\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion.png\" alt=\"\" width=\"1577\" height=\"330\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion.png 1577w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-300x63.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-1024x214.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-768x161.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-1536x321.png 1536w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-390x82.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-820x172.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/implicit-conversion-1180x247.png 1180w\" sizes=\"(max-width: 1577px) 100vw, 1577px\" \/><\/p>\n<h2 id=\"explicit-conversion\" style=\"text-align: justify;\"><strong>Explicit Conversion<\/strong><\/h2>\n<ul style=\"text-align: justify;\">\n<li>In python explicit conversion data type is manually changed by the user as per their requirement.\n<ul style=\"text-align: justify;\">\n<li>Int () function converts<strong>any data type to integer<\/strong>. \u2018Base\u2019 specifies the<strong>\u00a0base in which string is<\/strong>\u00a0if the data type is a string.<\/li>\n<li>Float () function is used to convert <strong>any data type to a <\/strong>floating-point number.<\/li>\n<li>Ord () function is used to convert a character to integer.<\/li>\n<li>Hex () function is used to convert integer to hexadecimal string.<\/li>\n<li>Oct () function is used to convert integer to octal string.<\/li>\n<li>Tuple () function is used to convert to a tuple.<\/li>\n<li>Set () function returns the type after converting to a set.<\/li>\n<li>List () function is used to convert any data type to a list type.<\/li>\n<li>Dict () function is used to convert a tuple of order into a dictionary.<\/li>\n<li>Str () function is used to convert integer into a string.<\/li>\n<li>Complex () function converts real numbers to complex number.<\/li>\n<li>Chr () function converts number to its corresponding ASCII character.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"sample-code-2\" style=\"text-align: justify;\"><strong>Sample Code<\/strong><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-python code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-python code-embed-code\"># Python code to demonstrate Type conversion<br\/><br\/># using\u00a0 tuple(), set(), list()<br\/><br\/># initializing string<br\/><br\/>s = &#039;geeks&#039;\u00a0\u00a0<br\/><br\/># printing string converting to tuple<br\/><br\/>c = tuple(s)<br\/><br\/>print (&quot;After converting string to tuple : &quot;,end=&quot;&quot;)<br\/><br\/>print (c)<br\/><br\/># printing string converting to set<br\/><br\/>c = set(s)<br\/><br\/>print (&quot;After converting string to set : &quot;,end=&quot;&quot;)<br\/><br\/>print (c)\u00a0<br\/><br\/># printing string converting to list<br\/><br\/>c = list(s)<br\/><br\/>print (&quot;After converting string to list : &quot;,end=&quot;&quot;)<br\/><br\/>print (c)<\/code><\/pre> <\/div>\n<h3 id=\"output-2\" style=\"text-align: justify;\"><strong>Output<\/strong><\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4722\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion.png\" alt=\"\" width=\"1596\" height=\"287\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion.png 1596w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-300x54.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-1024x184.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-768x138.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-1536x276.png 1536w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-390x70.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-820x147.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/explicit-conversion-1180x212.png 1180w\" sizes=\"(max-width: 1596px) 100vw, 1596px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming. The types conversion consists of two types, they are implicit conversion and explicit conversion. \u00a0Implicit Conversion In python implicit type conversion data types automatically converts one data type to another without any user involvement. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[5608],"tags":[18236,18243,18237,18235,18233,18238,18234,18241,18232,18242,18240,18239],"class_list":["post-4719","post","type-post","status-publish","format-standard","hentry","category-python","tag-difference-between-type-casting-and-type-conversion-in-python","tag-explain-type-conversion-in-python","tag-explicit-type-conversion-example","tag-explicit-type-conversion-in-python","tag-implicit-and-explicit-type-conversion-in-python","tag-python-type-casting-custom-class","tag-type-conversion-in-python","tag-what-is-data-type-conversion-in-python","tag-what-is-implicit-type-conversion-in-python","tag-what-is-the-importance-of-type-conversion-in-python","tag-what-is-type-conversion-in-python","tag-what-is-type-conversion-in-python-with-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is type conversion in python ? - Python Type Conversion - Wikitechy<\/title>\n<meta name=\"description\" content=\"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.\" \/>\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.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is type conversion in python ? - Python Type Conversion - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-16T11:55:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/\",\"name\":\"What is type conversion in python ? - Python Type Conversion - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png\",\"datePublished\":\"2022-08-16T11:55:14+00:00\",\"dateModified\":\"2022-08-16T11:55:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png\",\"width\":727,\"height\":412},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is type conversion in python ? - Python Type Conversion - Wikitechy","description":"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.","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.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/","og_locale":"en_US","og_type":"article","og_title":"What is type conversion in python ? - Python Type Conversion - Wikitechy","og_description":"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/","og_site_name":"Wikitechy","article_published_time":"2022-08-16T11:55:14+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/","name":"What is type conversion in python ? - Python Type Conversion - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png","datePublished":"2022-08-16T11:55:14+00:00","dateModified":"2022-08-16T11:55:14+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is type conversion in python ? - In python type casting functions to directly convert one data type to another which is useful in day-to-day and competitive programming.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-type-conversion-in-python\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/types-conversion.png","width":727,"height":412},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4719"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4719\/revisions"}],"predecessor-version":[{"id":4723,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4719\/revisions\/4723"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}