{"id":113522,"date":"2025-11-25T12:23:39","date_gmt":"2025-11-25T06:53:39","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=113522"},"modified":"2025-11-25T11:42:39","modified_gmt":"2025-11-25T06:12:39","slug":"python-type-casting","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/","title":{"rendered":"Learn Python Type Casting"},"content":{"rendered":"\n<h1 id=\"python-type-casting-how-to-convert-data-types\">Python Type Casting: How to Convert Data Types<\/h1>\n\n<h2 id=\"what-is-type-casting\">What Is Type Casting?<\/h2>\n<p>\n    Type casting is the process of converting a variable from one data type to another. It helps you perform operations that wouldn't work with the original data type. This helps you avoid errors and ensures your code behaves as expected.\n<\/p>\n<p>\n    For example, you can't add a number and a string together. First, you must convert the string to a number.\n<\/p>\n\n\n<h2 id=\"how-to-convert-data-types-in-python\">How to Convert Data Types in Python<\/h2>\n<p>\n    Python has simple, built-in functions for type casting. The three most common are <code>int()<\/code>, <code>float()<\/code>, and <code>str()<\/code>. Each function takes a value and converts it to the specified type.\n<\/p>\n\n<h3 id=\"1-converting-to-an-integer-with-int\">1. Converting to an Integer with <code>int()<\/code><\/h3>\n<p>\n    The <code>int()<\/code> function converts a value into an integer, which is a whole number. You can give it a float or a string, and it returns a whole number.\n<\/p>\n\n<h4 id=\"converting-float-to-integers\">Converting Float to Integers<\/h4>\n<p>\n    When you convert a float to an integer, the <code>int()<\/code> function truncates the value. This means it cuts off the decimal part completely without rounding the number.\n<\/p>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-int-float\" class=\"python-code-editor\">\nfloat_value = 15.75\ninteger_value = int(float_value)\n\nprint(\"Original:\", float_value)\nprint(\"Converted:\", integer_value)\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-int-float', 'output-int-float')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-int-float', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-int-float\" class=\"code-solution\">\n        <pre><code>float_value = 15.75\ninteger_value = int(float_value)\nprint(integer_value)<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-int-float\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-int-float\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h4 id=\"converting-strings-to-integers\">Converting Strings to Integers<\/h4>\n<p>\n    You can also convert a string to an integer, but only if the string contains a whole number. If the string has any non-numeric characters, Python raises a <code>ValueError<\/code>.\n<\/p>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-int-str\" class=\"python-code-editor\">\nnumeric_string = \"250\"\n# Convert string to int to perform math\nconverted_integer = int(numeric_string)\n\nprint(converted_integer * 2)\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-int-str', 'output-int-str')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-int-str', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-int-str\" class=\"code-solution\">\n        <pre><code>numeric_string = \"250\"\nconverted_integer = int(numeric_string)\nprint(converted_integer * 2)<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-int-str\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-int-str\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h3 id=\"2-converting-to-a-float-with-float\">2. Converting to a Float with <code>float()<\/code><\/h3>\n<p>\n    The <code>float()<\/code> function converts a value into a floating-point number (a number with decimals). Use this when you need decimal precision in calculations. It works with integers and compatible strings.\n<\/p>\n\n<h4 id=\"converting-integers-to-floats\">Converting Integers to Floats<\/h4>\n<p>\n    When you convert an integer to a float, the function adds a decimal point and a zero (<code>.0<\/code>) to the end.\n<\/p>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-float-int\" class=\"python-code-editor\">\nmy_integer = 42\nmy_float = float(my_integer)\n\nprint(my_float)\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-float-int', 'output-float-int')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-float-int', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-float-int\" class=\"code-solution\">\n        <pre><code>my_integer = 42\nmy_float = float(my_integer)\nprint(my_float)<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-float-int\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-float-int\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h4 id=\"converting-strings-to-floats\">Converting Strings to Floats<\/h4>\n<p>\n    If you convert a string, it must represent a valid number. This can be either an integer or a float.\n<\/p>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-float-str\" class=\"python-code-editor\">\npi_string = \"3.14159\"\npi_float = float(pi_string)\n\nprint(pi_float)\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-float-str', 'output-float-str')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-float-str', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-float-str\" class=\"code-solution\">\n        <pre><code>pi_string = \"3.14159\"\npi_float = float(pi_string)\nprint(pi_float)<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-float-str\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-float-str\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n\n\n<h3 id=\"3-converting-to-a-string-with-str\">3. Converting to a String with <code>str()<\/code><\/h3>\n<p>\n    You can convert almost any Python object into a string with the <code>str()<\/code> function. This works best when you want to combine numbers with text for display. For example, <code>str(10.5)<\/code> returns the string <code>\"10.5\"<\/code>.\n<\/p>\n\n<h4 id=\"why-you-need-str\">Why You Need <code>str()<\/code><\/h4>\n<p>\n    You often need <code>str()<\/code> when you want to print a message that includes a number. Python can't directly add a string and a number together, so you must first convert the number to a string.\n<\/p>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-str\" class=\"python-code-editor\">\nuser_age = 30\n\n# This works correctly\nprint(\"The user's age is: \" + str(user_age))\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-str', 'output-str')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-str', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-str\" class=\"code-solution\">\n        <pre><code>user_age = 30\nprint(\"The user's age is: \" + str(user_age))<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-str\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-str\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h2 id=\"common-use-cases-for-type-casting\">Common Use Cases for Type Casting<\/h2>\n<p>\n    You'll use type casting in several common situations:\n<\/p>\n<ul>\n    <li><strong>Process user input:<\/strong> The <code>input()<\/code> function always returns a string, so you need to convert it to work with numbers.<\/li>\n    <li><strong>Perform mathematical calculations:<\/strong> When you get data from files or APIs, you often need to convert it before doing math.<\/li>\n    <li><strong>Format output messages:<\/strong> You combine text with numbers, booleans, or other data types for display.<\/li>\n<\/ul>\n\n<h2 id=\"potential-errors-to-avoid\">Potential Errors to Avoid<\/h2>\n<p>\n    The most common issue you'll encounter with type casting is the <code>ValueError<\/code>. This error happens when you pass an incompatible value to a conversion function. For example, <code>int(\"hello\")<\/code> fails because Python can't interpret \"hello\" as a whole number.\n<\/p>\n<p>\n    You should validate data before you try to cast it. This matters especially when you work with user input, since users may enter data in unexpected formats. You can use methods like <code>str.isdigit()<\/code> or a try-except block to handle conversion errors smoothly.\n<\/p>\n\n<h4 id=\"example\">Example:<\/h4>\n<div class=\"code-editor-container\">\n    <div id=\"editor-error\" class=\"python-code-editor\">\ninvalid_input = \"hello\"\nprint(int(invalid_input))\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-error', 'output-error')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-error', this)\">Show Example<\/button>\n    <\/div>\n\n    <div id=\"solution-error\" class=\"code-solution\">\n        <pre><code>#This will work, as input is whole number\nvalid_input = \"123\"\nprint(int(valid_input))\n<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-error\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-error\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n<h2 id=\"final-challenge-the-bill-calculator\">Final Challenge: The Bill Calculator<\/h2>\n<p>\n    Put your skills to the test! You have a price as a string and a tax rate as a float.\n<\/p>\n<p>Your Task:<\/p>\n<ol>\n    <li>Convert the price string to a float.<\/li>\n    <li>Calculate the total cost (price + tax).<\/li>\n    <li>Convert the total back to a string to print a final message.<\/li>\n<\/ol>\n\n<div class=\"code-editor-container\">\n    <div id=\"editor-final\" class=\"python-code-editor\">\nitem_price = \"50.00\"\ntax_amount = 4.50\n\n# TODO: Convert item_price to float\n# price_float = ...\n\n# TODO: Calculate total\n# total = ...\n\n# TODO: Convert total to string and print message\n# print(\"Total is: \" + ...)\n    <\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-final', 'output-final')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-final', this)\">Show Solution<\/button>\n    <\/div>\n\n    <div id=\"solution-final\" class=\"code-solution\">\n        <pre><code>item_price = \"50.00\"\ntax_amount = 4.50\n\nprice_float = float(item_price)\ntotal = price_float + tax_amount\n\nprint(\"Total is: \" + str(total))<\/code><\/pre>\n    <\/div>\n\n    <label for=\"output-final\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-final\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<div class=\"cta-final\">\n    <div class=\"cta-final-header\">\n        <span class=\"cta-final-trophy\">\ud83c\udfc6<\/span>\n        <h2 id=\"lesson-completed\">Lesson Completed<\/h2>\n    <\/div>\n\n    <p class=\"cta-final-intro\">\n        You have successfully learned about Python Type Casting, including int(), float(), str(), and how to avoid ValueErrors.\n    <\/p>\n\n    <div class=\"cta-final-grid\">\n        <div class=\"cta-final-option\">\n            <div class=\"cta-final-option-header\">\n                <span>\ud83d\udcd8<\/span>\n                <h4 id=\"full-python-course\">Full Python Course<\/h4>\n            <\/div>\n            <p>Master Python with 11+ hours of content, 50+ exercises, and real-world projects.<\/p>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming?utm_source=blog\" class=\"cta-final-button-primary\">Enroll Now<\/a>\n        <\/div>\n\n        <div class=\"cta-final-option\" id=\"pt-next-lesson-container\">\n            <div class=\"cta-final-option-header\">\n                <span>\ud83d\udcdd<\/span>\n                <h4 id=\"next-lesson\">Next Lesson<\/h4>\n            <\/div>\n            <p id=\"pt-next-lesson-text\">Continue with the next lesson on Python User Input.<\/p>\n            <a href=\"#\" id=\"pt-next-lesson-button\" class=\"cta-final-button-secondary\">Next Lesson -><\/a>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.<\/p>\n","protected":false},"author":41,"featured_media":113536,"parent":113156,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"templates\/python-tutorial.php","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796,36893],"class_list":["post-113522","page","type-page","status-publish","has-post-thumbnail","hentry","category-software","tag-python","tag-python-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Learn Python Type Casting<\/title>\n<meta name=\"description\" content=\"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.\" \/>\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.mygreatlearning.com\/blog\/python\/python-type-casting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Python Type Casting\" \/>\n<meta property=\"og:description\" content=\"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Learn Python Type Casting\",\"datePublished\":\"2025-11-25T06:53:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/\"},\"wordCount\":750,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-type-casting.webp\",\"keywords\":[\"python\",\"python-tutorial\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/\",\"name\":\"Learn Python Type Casting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-type-casting.webp\",\"datePublished\":\"2025-11-25T06:53:39+00:00\",\"description\":\"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-type-casting.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-type-casting.webp\",\"width\":1408,\"height\":768,\"caption\":\"Python Type Casting\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-type-casting\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Tutorial\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Learn Python Type Casting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Learn Python Type Casting","description":"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.","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.mygreatlearning.com\/blog\/python\/python-type-casting\/","og_locale":"en_US","og_type":"article","og_title":"Learn Python Type Casting","og_description":"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Learn Python Type Casting","datePublished":"2025-11-25T06:53:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/"},"wordCount":750,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp","keywords":["python","python-tutorial"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/","name":"Learn Python Type Casting","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp","datePublished":"2025-11-25T06:53:39+00:00","description":"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp","width":1408,"height":768,"caption":"Python Type Casting"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-type-casting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Tutorial","item":"https:\/\/www.mygreatlearning.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Learn Python Type Casting"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-type-casting-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn Python type casting and how to convert data types using functions like int(), float(), and str(). Master conversion techniques to handle different data formats.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=113522"}],"version-history":[{"count":14,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113522\/revisions"}],"predecessor-version":[{"id":113533,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113522\/revisions\/113533"}],"up":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/113536"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=113522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=113522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=113522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}