{"id":2086,"date":"2020-07-31T18:19:57","date_gmt":"2020-07-31T12:49:57","guid":{"rendered":"https:\/\/copyassignment.com\/?page_id=2086"},"modified":"2022-08-29T13:58:07","modified_gmt":"2022-08-29T08:28:07","slug":"python-numeric-datatypes","status":"publish","type":"page","link":"https:\/\/copyassignment.com\/python\/python-numeric-datatypes\/","title":{"rendered":"Python Numeric Datatypes"},"content":{"rendered":"\n<p class=\"has-medium-font-size\">There are three Python Numeric Datatypes<span style=\"color:#ff2a05\" class=\"has-inline-color\"> <\/span><strong><span class=\"has-inline-color has-vivid-red-color\">int<\/span><\/strong>,<strong><em><span style=\"color:#ff0000\" class=\"has-inline-color\"> <\/span><\/em><span class=\"has-inline-color has-vivid-red-color\">float<\/span><\/strong>, <strong><span class=\"has-inline-color has-vivid-red-color\">complex<\/span>,<\/strong> and in mathematics, these are represented as <strong><span class=\"has-inline-color has-vivid-red-color\">integers<\/span><\/strong>, <strong><span class=\"has-inline-color has-vivid-red-color\">decimals<\/span><\/strong>, and <strong><span class=\"has-inline-color has-vivid-red-color\">complex <\/span><\/strong>numbers.<\/p>\n\n\n\n<div class=\"maindiv\"><h3>Example<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">x = 12\ny = 12.3\nz = 12j  # we use \"j\" to represant complex numbers\nprint(type(x))\nprint(type(y))\nprint(type(z))\n<\/pre><\/strong>\n<\/div><h3>Output<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">&lt;class 'int'&gt;\n&lt;class 'float'&gt;\n&lt;class 'complex'&gt;<\/pre><\/strong><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Int<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">In Python<strong><em><span style=\"color:#ff0004\" class=\"has-inline-color\"> <\/span><\/em><span class=\"has-inline-color has-vivid-red-color\">int<\/span><\/strong>, or<strong><em><span style=\"color:#ff0011\" class=\"has-inline-color\"> <\/span><\/em><\/strong><span class=\"has-inline-color has-vivid-red-color\"><strong>integer<\/strong> <\/span>is a whole number(positive, negative, and zero) and the length is unlimited.<\/p>\n\n\n\n<div class=\"maindiv\"><h3>Example<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">x = 1227348742474\ny = -12234353546\nz = 0\nprint(type(x))\nprint(type(y))\nprint(type(z))\n<\/pre><\/strong>\n<\/div><h3>Output<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">&lt;class 'int'&gt;\n&lt;class 'int'&gt;\n&lt;class 'int'&gt;<\/pre><\/strong><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Float<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">In Python <strong><span class=\"has-inline-color has-vivid-red-color\">&#8220;Float<\/span><\/strong><span class=\"has-inline-color has-vivid-red-color\"><strong>&#8220;<\/strong><\/span><em><strong><span style=\"color:#ff0000\" class=\"has-inline-color\"> <\/span><\/strong><\/em>or<span class=\"has-inline-color has-vivid-red-color\"> <strong>&#8220;floating-point numbers&#8221;<\/strong><\/span><strong> <\/strong>are similar to decimal numbers in maths.<\/p>\n\n\n\n<div class=\"maindiv\"><h3>Example<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">x = 122734.8742474\ny = -12234.353546\nz = 0.2032\nprint(type(x))\nprint(type(y))\nprint(type(z))\n<\/pre><\/strong>\n<\/div><h3>Output<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">&lt;class 'float'&gt;\n&lt;class 'float'&gt;\n&lt;class 'float'&gt;<\/pre><\/strong><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Complex<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">In Python, <span class=\"has-inline-color has-vivid-red-color\"><strong>&#8220;complex numbers<\/strong>&#8221; <\/span>are created using <span class=\"has-inline-color has-vivid-red-color\"><strong>&#8220;j&#8221;<\/strong><\/span> after a number.<\/p>\n\n\n\n<div class=\"maindiv\"><h3>Example<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">x = 12 + 3j\ny = -12 - 0.4j\nz = 4j\nprint(type(x))\nprint(type(y))\nprint(type(z))\n<\/pre><\/strong>\n<\/div><h3>Output<\/h3><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">&lt;class 'complex'&gt;\n&lt;class 'complex'&gt;\n&lt;class 'complex'&gt;<\/pre><\/strong><\/div><\/div>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-text-color has-background\" href=\"https:\/\/copyassignment.com\/python\/python-datatypes\/\" style=\"background-color:#4caf50;color:#ffffff\">Previous&#8211; Python Datatypes<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-text-color has-background\" href=\"https:\/\/copyassignment.com\/python\/python-strings\/\" style=\"background-color:#4caf50;color:#ffffff\">Next&#8211; Python Strings<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p class=\"has-large-font-size\"><strong>Also Read:<\/strong><\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>There are three Python Numeric Datatypes int, float, complex, and in mathematics, these are represented as integers, decimals, and complex numbers. Example x = 12&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":833,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"template-s1-c-page.php","meta":{"footnotes":""},"class_list":["post-2086","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/pages\/2086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=2086"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/pages\/2086\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/pages\/833"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=2086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}