Python Tutorial

Introduction Python Features Python Applications System requirements for Python Python Installation Python Basics Python Variables Python Data Types Python IDE Python Keywords Python Operators Python Comments Python Pass Statement

Python Conditional Statements

Python if Statement Python elif Statement Python If-else statement Python Switch Case

Python Loops

Python for loop Python while loop Python Break Statement Python Continue Statement Python Goto Statement

Python Arrays

Python Array Python Matrix

Python Strings

Python Strings Python Regex

Python Built-in Data Structure

Python Lists Python Tuples Python Lists vs Tuples Python Dictionary Python Sets

Python Functions

Python Function Python min() function Python max() function Python User-define Functions Python Built-in Functions Anonymous/Lambda Function in Python

Python File Handling

Python File Handling Python Read CSV Python Write CSV Python Read Excel Python Write Excel Python Read Text File Python Write Text File Read JSON File in Python

Python Exception Handling

Python Exception Handling Python Errors and exceptions Python Assert

Python OOPs Concept

OOPs Concepts in Python Classes & Objects in Python Inheritance in Python Polymorphism in Python Python Encapsulation Python Constructor Static Variables in Python Abstraction in Python

Python Iterators

Iterators in Python Yield Statement In Python

Python Generators

Python Generator

Python Decorators

Python Decorator

Python Functions and Methods

Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods

Python Modules

Python Modules Python Datetime Module Python Calendar Module  

Python MySQL

Python MySQL Python MySQL Update Operation Python MySQL Delete Operation

Python MongoDB

Python MongoDB

Python Data Structure Implementation

Python Stack Python Queue Python Hash Table Python Graph

Python Advance Topics

Speech Recognition in Python Face Recognition in Python Python Rest API Python Command Line Arguments Python JSON Python Virtual Environment Type Casting in Python Collections in python Python Enumerate Python Debugger Python DefaultDict


Python PPTX Python Pickle Python Seaborn Python Coroutine Python EOL Python Infinity Python math.cos and math.acos function Python Project Ideas Based On Django Reverse a String in Python Reverse a Number in Python Python Word Tokenizer Python Trigonometric Functions Python try catch exception GUI Calculator in Python Implementing geometric shapes into the game in python Installing Packages in Python Python Try Except Python Sending Email Socket Programming in Python Python CGI Programming Python Data Structures Python abstract class Python Compiler Python K-Means Clustering List Comprehension in Python3 NSE Tools In Python Operator Module In Python Palindrome In Python Permutations in Python Pillow Python introduction and setup Python Functionalities of Pillow Module Python Argmin Python whois Python JSON Schema Python lock Return Statement In Python Reverse a sentence In Python tell() function in Python Why learn Python? Write Dictionary to CSV in Python Write a String in Python Binary Search Visualization using Pygame in Python Latest Project Ideas using Python 2022 Closest Pair of Points in Python ComboBox in Python Python vs R Python Ternary Operators Self in Python Python vs Java Python Modulo Python Packages Python Syntax Python Uses Python Logical Operators Python Multiprocessing Python History Difference between Input() and raw_input() functions in Python Conditional Statements in python Confusion Matrix Visualization Python Python Algorithms Python Modules List Difference between Python 2 and Python 3 Is Python Case Sensitive Method Overloading in Python Python Arithmetic Operators Design patterns in python Assignment Operators in Python Is Python Object Oriented Programming language Division in Python Python exit commands Continue And Pass Statements In Python Colors In Python Convert String Into Int In Python Convert String To Binary In Python Convert Uppercase To Lowercase In Python Convert XML To JSON In Python Converting Set To List In Python Covariance In Python CSV Module In Python Decision Tree In Python Difference Between Yield And Return In Python Dynamic Typing In Python Abstract design pattern in python Builder design pattern in python Prototype design pattern in Python Creational design patterns in Python

How to

How to convert integer to float in Python How to reverse a string in Python How to take input in Python How to install Python in Windows How to install Python in Ubuntu How to install PIP in Python How to call a function in Python How to download Python How to comment multiple lines in Python How to create a file in Python How to create a list in Python How to declare array in Python How to clear screen in Python How to convert string to list in Python How to take multiple inputs in Python How to write a program in Python How to compare two strings in Python How to create a dictionary in Python How to create an array in Python How to update Python How to compare two lists in Python How to concatenate two strings in Python How to print pattern in Python How to check data type in python How to slice a list in python How to implement classifiers in Python How To Print Colored Text in Python How to develop a game in python How to print in same line in python How to create a class in python How to find square root in python How to import numy in python How to import pandas in python How to uninstall python How to upgrade PIP in python How to append a string in python How to open a file in python


Python Sort List Sort Dictionary in Python Python sort() function Python Bubble Sort


Factorial Program in Python Prime Number Program in Python Fibonacci Series Program in Python Leap Year Program in Python Palindrome Program in Python Check Palindrome In Python Calculator Program in Python Armstrong Number Program in Python Python Program to add two numbers Anagram Program in Python Even Odd Program in Python GCD Program in Python Python Exit Program Python Program to check Leap Year Operator Overloading in Python Pointers in Python Python Not Equal Operator Raise Exception in Python Salary of Python Developers in India What is a Script in Python Singleton design pattern in python

How to convert integer to float in Python

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses an interpreter instead of the compiler to run the code. The interpreted language is processed at the run time thus takes less time to run. Python is also interactive, so we can directly run programs in the terminal itself.

In this article, we are going to discuss how to convert an integer data type to a float data type. Datatypes are the categorization of the data items. Every value in Python has its datatype. The classification of data items to put in some category is called data types. As we know, Python is an object-oriented programming language, and everything in Python is an object. Data types represent classes, and the instance of these classes are called variables.

These are the built-in data types in Python:

  • Set Types: set
  • Mapping: dict
  • Boolean: Bool
  • Numeric Types: Integer, Float, Complex
  • Binary Types: Bytes, Bytearray
  • Sequence Types: List, Tuples
  • Text Types: String

There are three types of Numeric Datatype in Python. Both Integer and Float are categorized into Numeric Data Types. Numeric data types take the numeric value. These data types are created when a value is assigned to them. For example, var = 12.2 will assign a memory block to var with the value 12.2. In Python, we can also delete the variable using the del keyword, thus freeing up the memory.

  • Int:  They are positive or negative integer objects numbers without any decimal. The size of the integer is limited by memory. We can also define the integers in other representations like binary, octal etc.
  • Float: The float data type is used to store the decimal point negative and non-negative integers. We can also define float with scientific notation forex: number 1.2e2 represents 120.0.
  • Complex: Complex numbers are those which has an imaginary number in them. These numbers cannot be represented in the number line. Complex numbers are represented with a + ib where i is (-1)1/2.

Number Type Conversion

Type conversion functions are defined in Python to convert data types. In Python, we can convert one data type to another. Conversing data types is very useful in day to day life or while solving coding questions.

We can do Data Conversion in two ways in Python, either to let the compiler decide itself the data type of the variable or to specifically tell the compiler to convert the data type of a variable to which data type. The former is called the Implicit Type Conversion, and the latter is the Explicit Type Conversion.

Let us discuss these types of conversions in detail:

Implicit Data Type Conversion

Implicit Type conversion which is also known as Coercion is when converting data type take place during compilation time and is done by compiler itself for us. To get the better understanding of the topic let us see an example below:

x = 10

print("Data type of x is: ",type(x))

y = 10.5

print("Data type of y is: ",type(y))

z = x + y

print("Sum of x and y is: ",z)

print("Data type of z is: ",type(x))


Data type of x is:  <class 'int'>

Data type of y is:  <class 'float'>

Sum of x and y is:  20.5

Data type of z is:  <class 'int'>
How To Convert Integer To Float In Python
  • In the above code, we have defined two variables, x and y.
  • In this code, x is of data type int, and y is of data type float. We can use the in-built type() function to check the data type in Python.
  • Then we have added the two variables x and y and storing the sum in z.
  • The datatype of z is of type float. This is called the implicit data type conversion.

You might have a question that why the data type of z is not an integer. This is because of the concept of type promotion in computer science. The compiler converts the data into the data type, which does not cause the loss of information. Python always converts the smaller data type to a larger one. So the data type of z is not defined as an integer because it will cause the loss of information since integers cannot hold decimal numbers.

Explicit Data Type Conversion

In Explicit Type Conversion, the user's data type conversion is done manually as per the requirements. Explicit Conversion is also referred to as Type Casting because the user casts the datatype to which he wants to convert to. To do the type conversion we use some pre-defined functions like float(), int(), str(), etc.

The general syntax of explicitly converting data type is:


With the explicit data type conversion, there is a risk of loss of information since we are forcing a data type to a variable.

The data types are classified into two data structures Primitive and Non-Primitive.

Primitive Data Structure

These are the primary data structure and are the building blocks in Python. They are the primary data structure for data manipulation.

Some forms of explicit Conversion in the primitive data structure are described below:

  • Int(): It is used to convert the data type to integer.
  • Float(): It is used to convert any data type to a floating integer.
  • Hex(): Hex is used to convert an integer to a hexadecimal string.
  • Oct(): Oct is used to convert integer to octal decimal.
  • Ord(): It is used to convert a data type to a string.

Let us see some examples of type conversion.

Integer to Float:

Num1 = 123

Num2 = 324

Num3  = float(Num1+ Num2)

Print(Num3, type(Num3))


447.0 <class 'float'>

Addition of String to Integer

num = 123

str = "321"

print("Data type of int:",type(num))

print("Data type of str:",type(str))

str = int(str)

print("Data type of str after Type Casting:",type(str))

sum = num + str

print("Sum of num and str:",sum)

print("Data type of the sum:",type(sum))


Data type of int: <class 'int'>

Data type of str: <class 'str'>

The data type of str after Type Casting: <class 'int'>

Sum of num and str: 444

The data type of the sum: <class 'int'>

Non-Primitive Data Structure

Non-Primitive data structure stores the collection of primitive data structures. The non-primitive data structures are Lists, Tuple, Dictionaries, etc.

Some forms of explicit Conversion in the non-primitive data structure are described below:

  • Tuple(): Tuple is used to convert a data type to tuples.
  • List(): List is used to converting a data type to lists.
  • Set(): Set is used to convert a data type to sets.
  • Dict(): Dict is used to convert a data type to dictionaries.
#Data Type Conversion to Tuple, Set and List

str = 'javatpoint'

# converting to tuple

tup= tuple(str)

print ("After converting string to tuple : ",end="")

print (tup)

# converting to set

st = set(str)

print ("After converting string to set : ",end="")

print (st)

# converting to list

lst = list(str)

print ("After converting string to list : ",end="")

print (lst)


After converting string to tuple : ('j', 'a', 'v', 'a', 't', 'p', 'o', 'i', 'n', 't')

After converting string to set : {'p', 'j', 'i', 'a', 't', 'v', 'n', 'o'}

After converting string to list : ['j', 'a', 'v', 'a', 't', 'p', 'o', 'i', 'n', 't']
How To Convert Integer To Float In Python