Intellipaat

Intellipaat

Explore Online Courses Free Courses Hire from us Become an Instructor Reviews
All Courses
  • Articles
  • Tutorials
  • Interview Questions
Home > Blog > Tutorials > Python Tutorial For Beginners > Type Conversion in Python

Type Conversion in Python

By Lithin Reddy | Last updated on October 14, 2025 | 88089 Views
Share this article
Previous
Next
Tutorial Playlist
    • Python Tutorial For Beginners
    • Python Itertools
    • How to use Python numpy.where() Method?
    • Python Break & Continue statements
    • What Does “elif” Mean in Python?
    • Magic Methods In Python
    • Python Fundamentals - Learn Python Basics
    • Introduction and History of Python
    • What is Python Programming Language?
    • Python Version History
    • Top 10 Python Frameworks
    • Python Download - How To Install Python [Easy Steps]
    • Python Syntax: A Guide To Writing Basic Python Code
    • What are comments in python
    • Python Input and Output Commands
    • Python Data Types: Complete Guide with Examples (2026)
    • Python Variables
    • Python Numbers - Learn How to Create Prime Numbers, Perfect Numbers, and Reverse Numbers in Python
    • Strings in Python
    • Python Lists - A Complete Guide (With Syntax and Examples)
    • Tuples in Python
    • Python Set - The Basics
    • Dictionaries in Python - From Key-Value Pairs to Advanced Methods
    • Python Operators
    • Python Modules, Regular Expressions & Python Frameworks
    • Type Conversion in Python
    • Python If Else Statements - Conditional Statements with Examples
    • Python While Loop
    • Python for Loops - A Step-by-Step Guide
    • Python Function - Example & Syntax
    • Python Lambda Functions - A Beginner's Guide
    • Python Built-in Functions
    • Python Arrays - The Complete Guide
    • Python Classes and Objects
    • Introduction to Python Modules
    • Python Datetime - A Guide to Work With Dates and Times in Python
    • Python JSON - Parsing, Creating, and Working with JSON Data
    • What is Regular Expression in Python
    • How to Install Pip in Python
    • File Handling in Python
    • Exception Handling in Python with Examples
    • Enumerate() in Python - A Detailed Explanation
    • Python Queue Tutorial: Queue Module, Deque & Priority Queue (2026)
    • Numpy - Features, Installation and Examples
    • SciPy in Python Tutorial
    • Python Scikit-Learn
    • Python Pandas - Features and Use Cases (With Examples)
    • Introduction to Matplotlib in Python
    • Python Cheat Sheet - Basics to Regex, Syntax, and Data Types [UPDATED]
    • Data Structures with Python Cheat Sheet
    • NumPy Cheat Sheet
    • Scikit-Learn Cheat Sheet: Python Machine Learning
    • Pandas Cheat Sheet
    • List Comprehension in Python
    • Web Scraping with Python - A Step-by-Step Tutorial
    • Python Tutorial For Beginners
    • Python Itertools
    • How to use Python numpy.where() Method?
    • Python Break & Continue statements
    • What Does “elif” Mean in Python?
    • Magic Methods In Python
    • Python Fundamentals - Learn Python Basics
    • Introduction and History of Python
    • What is Python Programming Language?
    • Python Version History
    • Top 10 Python Frameworks
    • Python Download - How To Install Python [Easy Steps]
    • Python Syntax: A Guide To Writing Basic Python Code
    • What are comments in python
    • Python Input and Output Commands
    • Python Data Types: Complete Guide with Examples (2026)
    • Python Variables
    • Python Numbers - Learn How to Create Prime Numbers, Perfect Numbers, and Reverse Numbers in Python
    • Strings in Python
    • Python Lists - A Complete Guide (With Syntax and Examples)
    • Tuples in Python
    • Python Set - The Basics
    • Dictionaries in Python - From Key-Value Pairs to Advanced Methods
    • Python Operators
    • Python Modules, Regular Expressions & Python Frameworks
    • Type Conversion in Python
    • Python If Else Statements - Conditional Statements with Examples
    • Python While Loop
    • Python for Loops - A Step-by-Step Guide
    • Python Function - Example & Syntax
    • Python Lambda Functions - A Beginner's Guide
    • Python Built-in Functions
    • Python Arrays - The Complete Guide
    • Python Classes and Objects
    • Introduction to Python Modules
    • Python Datetime - A Guide to Work With Dates and Times in Python
    • Python JSON - Parsing, Creating, and Working with JSON Data
    • What is Regular Expression in Python
    • How to Install Pip in Python
    • File Handling in Python
    • Exception Handling in Python with Examples
    • Enumerate() in Python - A Detailed Explanation
    • Python Queue Tutorial: Queue Module, Deque & Priority Queue (2026)
    • Numpy - Features, Installation and Examples
    • SciPy in Python Tutorial
    • Python Scikit-Learn
    • Python Pandas - Features and Use Cases (With Examples)
    • Introduction to Matplotlib in Python
    • Python Cheat Sheet - Basics to Regex, Syntax, and Data Types [UPDATED]
    • Data Structures with Python Cheat Sheet
    • NumPy Cheat Sheet
    • Scikit-Learn Cheat Sheet: Python Machine Learning
    • Pandas Cheat Sheet
    • List Comprehension in Python
    • Web Scraping with Python - A Step-by-Step Tutorial
`; ip_get_section_iq.innerHTML = sidebarhtml_desk; playlistmobile.innerHTML = sidebarhtml_desk; var ip_iq_scriptToRemove = document.getElementById('ip-blog-iq-script-removal'); if (ip_iq_scriptToRemove) { ip_iq_scriptToRemove.remove(); } var activeSubmenuItems = document.querySelectorAll('.tutorial_list_submenu li.active'); activeSubmenuItems.forEach(function(activeItem) { var rootParentLi = activeItem.closest('.maincata'); if (rootParentLi) { rootParentLi.classList.add('opentutorialsubmenu'); } }); var ip_blog_tutorialListMenu = document.querySelector('.tutorial_list_menu'); if(ip_blog_tutorialListMenu){ var ip_blo_activeItem = ip_blog_tutorialListMenu.querySelector('li.active'); var lastlink = ''; var nextlink = ''; var total = 0; jQuery('#TutorialLeftArea .maincata ul').children('li').each(function(indexx) { total = indexx; }); jQuery('#TutorialLeftArea .maincata ul').children('li').each(function(i) { var isActive = jQuery(this).hasClass('active'); if(isActive){ if(i !== 0){ var lastIndexedElement = jQuery('#TutorialLeftArea .maincata ul').children('li').eq(i - 1); lastlink = lastIndexedElement.children('a').attr('href'); }else{ lastlink = ''; } if(total > i){ var nextIndexedElement = jQuery('#TutorialLeftArea .maincata ul').children('li').eq(i + 1); nextlink = nextIndexedElement.children('a').attr('href'); }else{ nextlink = ''; } return false; } }); var ip_blog_prevBlog = document.querySelector('.prev-blog a'); var ip_blog_nextBlog = document.querySelector('.next-blog a'); if (lastlink !== '' && typeof lastlink !== 'undefined') { ip_blog_prevBlog.setAttribute('href', lastlink); }else { if(ip_blog_prevBlog){ ip_blog_prevBlog.style.display = 'none'; } } if (nextlink !== '' && typeof nextlink !== 'undefined') { ip_blog_nextBlog.setAttribute('href', nextlink); }else { if(ip_blog_nextBlog){ ip_blog_nextBlog.style.display = 'none'; } } } function ip_blog_setActiveLink() { var divElements = document.querySelectorAll('div[id]'); var links = document.querySelectorAll('.interview-question-bookmark-list-alt li a'); var activeLink = null; divElements.forEach(function(div) { if (ip_blog_isInViewportThreshold(div, 50)) { var ip_blog_divId = div.getAttribute('id'); links.forEach(function(link) { if (link.getAttribute('href') === '#' + ip_blog_divId) { activeLink = link; } }); } }); links.forEach(function(link) { link.classList.remove('active'); }); if (activeLink) { activeLink.classList.add('active'); } } function ip_blog_isInViewportThreshold(element, threshold) { var rect = element.getBoundingClientRect(); var windowHeight = window.innerHeight || document.documentElement.clientHeight; var topThreshold = rect.top - threshold; var bottomThreshold = rect.bottom + threshold; return topThreshold <= windowHeight && bottomThreshold >= 0; } window.addEventListener('scroll', ip_blog_setActiveLink); window.addEventListener('load', ip_blog_setActiveLink); }); function ip_blg_findClosestAnchor(element) { while (element) { if (element.tagName === 'A') { return element; } element = element.parentNode; } return null; } function ip_bl_v_scrollToDiv(event_pb, offset) { event_pb.preventDefault(); const ip_bl_linkElement = ip_blg_findClosestAnchor(event_pb.target); if (ip_bl_linkElement) { const it_bl_hashValue = ip_bl_linkElement.getAttribute('href').substring(1); const it_blg_vf_targetElement = document.getElementById(it_bl_hashValue); if (it_blg_vf_targetElement) { jQuery('html, body').animate({ scrollTop: jQuery('#' + it_bl_hashValue).offset().top - offset }, 1000); } } } document.addEventListener('DOMContentLoaded', function() { let it_bl_offset = 0; const ip_blo_vi_anchorLinks = document.querySelectorAll('a[href^="#"]'); ip_blo_vi_anchorLinks.forEach(function(linkip_bg) { linkip_bg.addEventListener('click', function(event_pb) { setTimeout(function() { console.log('Offset passed during click: ' + it_bl_offset); ip_bl_v_scrollToDiv(event_pb, it_bl_offset); }, 0); }); }); });
See More

In Python, data type conversion refers to the process of transforming one data type to another, which is useful in everyday programming.

This tutorial covers type conversion in Python in detail, with examples and discussions of various types of conversions.

Table of Contents

      • What is Type Conversion in Python
      • Implicit Type Conversion in Python
      • Explicit Type Conversion in Python
      • Key Points to Remember While performing Type Conversion in Python
      • Conclusion

What is Type Conversion in Python?

Type conversionor typecasting in Python refers to changing one data type to another in order to make it more suitable for the operation you wish to perform. There are two types of type conversion in Python.

    • Implicit Type Conversion – automatic type conversion
    • Explicit Type Conversion – manual type conversion

Implicit Type Conversion in Python

In Python, when the data type conversion takes place during compilation or during the runtime, it’s called an implicit data type conversion. Python handles the implicit data type conversion, so we don’t have to explicitly convert the data type into another data type. We have seen various examples of this kind of data type conversion throughout the tutorial. Let’s see another example.

Let’s add two Python variables of two different data types and store the result in a variable and see if the Python compiler is able to convert the data type of the resultant variable or not.

Python
Code Copied!

In the above example, we have taken two variables of integer, and float data types and added them. Further, we have declared another variable named ‘sum’ and stored the result of the addition in it. When we checked the data type of the sum variable, we could see that the data type of the sum variable had been automatically converted into the float data type by the Python compiler. This is called implicit type conversion.

The reason that the sum variable was converted into the float data type and not the integer data type is that if the compiler had converted it into the integer data type, then it would’ve had to remove the fractional part, which would have resulted in data loss. So, Python always converts smaller data types into larger data types to prevent the loss of data.

Explicit Type Conversion in Python

Explicit type conversion is also known as typecasting. Explicit type conversion takes place when the programmer clearly and explicitly defines the same in the program. For explicit type conversion, there are some in-built Python functions. The following table contains some of the in-built functions for type conversion, along with their descriptions.

Function Description
int(y [base]) It converts y to an integer, and Base specifies the number base. For example, if you want to convert the string into decimal numbers then you’ll use 10 as the base.
float(y) It converts y to a floating-point number.
complex(real [imag]) It creates a complex number.
str(y) It converts y to a string.
tuple(y) It converts y to a tuple.
list(y) It converts y to a list.
set(y) It converts y to a set.
dict(y) It creates a dictionary and y should be a sequence of (key, value) tuples.
ord(y) It converts a character into an integer.
hex(y) It converts an integer to a hexadecimal string.
oct(y) It converts an integer to an octal string

Now that we know the in-built functions provided by Python that are used for explicit type conversion, let’s see the syntax for explicit type conversion:

(required_data type)(expression)

Let’s go over the following examples for explicit type conversion in Python.

Python
Code Copied!

In the above example, variable a is of the number data type, and variable b is of the string data type. When we try to add these two integers and store the value in a variable named result1, a TypeError occurs, as shown in the output. So, in order to perform this operation, we have to use explicit type casting.
As we can see in the above code block, we have converted the variable b into an int type and then added variables a and b. The sum is stored in the variable named result2, and when printed, it displays 300 as output, as we can see in the output block. Also, checking to see if a string is an integer or float.

Key Points to Remember While Performing Type Conversion in Python

    • Type conversion is the process of converting a data type into another data type.
    • Implicit type conversion is performed by a Python interpreter only.
    • Explicit type conversion is performed by the user by explicitly using type conversion functions in the program code.
    • Explicit type conversion is also known as typecasting.
    • Python, when performing implicit type casting, avoids the loss of data.

Get 100% Hike!

Master Most in Demand Skills Now!

Check out other Python Fundamentals and Concepts resources-

Identifier in Python – Examples and Advantages

What are tokens in Python and its types? – [UPDATED]

What is Floor Division in Python? With Examples [Updated 2025]

Advantages and Disadvantages of Python – Major Pros and Cons

Conclusion

We have now completed this module of the Python Tutorial. Now, if you want to know why Python is the most preferred language for Data Science, you can go through this blog on Python Data Science tutorial.
Now look into the  Python Certification Training for upgrading your career to new heights. Also, check out our Python Interview Questions For Freshers.

About the Author

Lithin Reddy
Lithin Reddy
Data Scientist | Technical Research Analyst - Analytics & Business Intelligence

Lithin Reddy is a Data Scientist and Technical Research Analyst with around 1.5 years of experience, specializing in Python, SQL, system design, and Power BI. Known for building robust, well-structured solutions and contributing clear, practical insights that address real-world development challenges.

Recommended Videos
Python Interview Questions And Answers
Python Interview Questions And Answers
Numpy Interview Questions For Freshers
Numpy Interview Questions For Freshers
Pandas Coding Interview Questions
Pandas Coding Interview Questions
OOPS Interview Questions and Answers
OOPS Interview Questions and Answers
Python Pandas Tutorial
Python Pandas Tutorial
Recommended Programs
Python Course
Python Course
5 (218118)
Free Python Certification Course Online
Free Python Certification Course Online
5 (53455)
Python Data Science Course
Python Data Science Course
5 (76533)
Software Development Engineering Course
Software Development Engineering Course
5 (23421)

Course Preview

Expert-Led No.1

Type Conversion in Python

Intellipaat

facebook twitter linkedin youtube insta telegram

Intellipaat

facebook twitter linkedin youtube insta telegram

Get Our App Now!

Intellipaat android app Intellipaat android app

Get Our App Now!

Intellipaat android app Intellipaat android app

Courses

  • Data Scientist Course
  • Machine Learning Course
  • Python Course
  • Devops Training
  • Business Analyst Certification
  • Cyber Security Courses
  • Business Analytics Training
  • Investment Banking Course
  • SQL Course
  • AWS DevOps Course
  • Full Stack Developer Course
  • Product Management Course

Courses

  • AWS Solutions Architect
  • UI UX Design Course
  • Salesforce Training
  • Selenium Training
  • Artificial Intelligence Course
  • Ethical Hacking Course
  • Azure Administrator Certification
  • Cyber Security Course
  • Digital Marketing Course
  • Electric Vehicle Course
  • Azure DevOps Course
  • Web Development Courses

Tutorials

  • Python Tutorial
  • AWS Tutorial
  • Devops Tutorial
  • Java Tutorial
  • Node Js Tutorial
  • Cyber Security Tutorial
  • Salesforce Tutorial
  • Azure Tutorial
  • Ethical Hacking Tutorial
  • Data Science Tutorial
  • Cloud Computing Courses
  • Python Data Science Course

Interview Questions

  • Python Interview Questions
  • AWS Interview Questions
  • Data Science Interview Questions
  • Devops Interview Questions
  • Salesforce Interview Questions
  • Java Interview Questions
  • SQL Interview Questions
  • React Interview Questions
  • Node Js Interview Questions
  • Digital Marketing Interview Questions

Browse By Domains

Data Science Salesforce Courses Cloud Computing Courses AI & Machine Learning Courses Project Management Courses Cyber Security and Ethical Hacking Courses Web Development Courses Job Oriented Courses Degree Courses Marketing CRM Courses Software Development Courses Doctorate Programs Undergraduate Courses Banking and Finance Courses Product Design Courses Electric and Hybrid Vehicle Courses Leadership & Management Courses Management Courses Generative AI Courses Design Thinking Courses Microsoft Certification Courses

Top Tutorials

Machine Learning Tutorial Power BI Tutorial SQL Tutorial Artificial Intelligence Tutorial Digital Marketing Tutorial Data Analytics Tutorial UI/UX Tutorial

Top Articles

Cloud Computing Data Science Machine Learning What is AWS Digital Marketing Cyber Security Salesforce Artificial Intelligence

Top Interview Questions

Selenium Interview Questions Azure Interview Questions Machine Learning Interview Questions Cyber Security Interview Questions Business Analyst Interview Questions and Answers C Interview Questions Data Analyst Interview Questions Software Engineering Interview Questions

© Copyright 2011 - 2026 Intellipaat Software Solutions Pvt. Ltd.
Media
Contact Us
Tutorials
Interview Questions

Address: 6th Floor, Primeco Towers, Arekere Gate Junction, Bannerghatta Main Road, Bengaluru, Karnataka 560076, India.

Disclaimer: The certification names are the trademarks of their respective owners.

INTPL_2026-05-22