Python int() Function

Last Updated : 29 Aug 2026

Python int() function is used to get the integer value. It returns an expression converted into an integer number. If the argument is a floating point, the conversion truncates the number. If the argument is outside the integer range, It converts the number into long type.

If the number is not a number or if a base is given, the number must be a string.

Syntax of int() Function

It has the following syntax:

Parameters

  • x : A number which is to be converted into integer type.
  • base: It is an Optional argument if used number must be a string.

Return Values

It returns an integer value.

Examples of Python int() Function

Let's see some examples of int() function to understand it's functionality.

Example 1: Using int() to Convert Float and String into Integer

It is a simple python example which converts float and string values into an integer type. The float value is truncated by the function and returned an integer instead.

Python

Execute Now

Output:

integer values : 10 10 10

Example 2: Using int() Function with Type Checking and Conversion

This example demonstrates how the int() function converts different data types into integers and how their types change after conversion.

Python

Execute Now

Output:

<class 'int'> <class 'float'> <class 'str'>
values after conversion  10 10 10
and types are: 
  <class 'int'> <class 'int'> <class 'int'>

Example 3: Using int() to Convert Different Number Systems

This example demonstrates how the int() function works with numbers from different number systems like binary, hexadecimal, and octal.

Python

Execute Now

Output:

Values after conversion: 2 175 8
and types are: 
  <class 'int'> <class 'int'> <class 'int'>