Python int() Function

Python Programming Training Certification


Flexible Hours

100 Assignments

Instructor Led online Training

50 LMS Access

24X7 Support

100% Skill Level

Enquire Now

4.9 out of 1000+ Ratings
Best Python Institute for Learning Python Course & Training, Live Project Training in Python with Django, Data Science and AI, Interview Assistance, Expert Coaching Trainers. Python Certification & Interview Assistance! Get free demo now!

Course Overview

Python is one of the world’s top programming languages used today and Python training has become the most popular training across individuals. Training Basket’s Python Training & Certification course covers basic and advanced Python concepts and how to apply them in real-world applications.Python is a flexible and powerful open-source language that is easy to learn and consists of powerful libraries for data analysis and manipulation. Our Python training course content is curated by experts as per the standard Industry curriculum. The curriculum, coding challenges and real-life problems cover data operations in Python, strings, conditional statements, error handling, shell scripting, web scraping and the commonly used Python web framework Django. Take this Python training and certification course and become job-ready now.

Python int() Function

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.

Signature

  • int(x, base=10)

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

It returns an integer value.

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

Python int() Function Example 1

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 int() function example
    # Calling function
    val = int(10) # integer value
    val2 = int(10.52) # float value
    val3 = int(’10’) # string value
    # Displaying result
    print(“integer values :”,val, val2, val3)

Output:

  • integer values : 10 10 10

Python int() Function Example 2

To verify the type of returned value, we can use type function. The type function returns the type of value. See an example below.

  • # Python int() function example
    # Declaring variables
    val1 = 10 # integer
    val2 = 10.52 # float
    val3 = ’10’ # string

    # Checking values’s type
    print(type(val1), type(val2), type(val3))
    # Calling int() function
    val4 = int(val1)
    val5 = int(val2)
    val6 = int(val3)
    # Displaying result
    print(“values after conversion “,val4, val5, val6)
    print(“and types are: \n “, type(val4), type(val5), type(val6))

Output:

  • <class ‘int’> <class ‘float’> <class ‘str’>
    values after conversion 10 10 10
    and types are:
    <class ‘int’> <class ‘int’> <class ‘int’>

Python int() Function Example 3

  • # Python int() function example
    # Declaring variables
    val1 = 0b010 # binary
    val2 = 0xAF # hexadecimal
    val3 = 0o10 # octal

    # Calling int() function
    val4 = int(val1)
    val5 = int(val2)
    val6 = int(val3)
    # Displaying result
    print(“Values after conversion:”,val4, val5, val6)
    print(“and types are: \n “, type(val4), type(val5), type(val6))

Output:

  • Values after conversion: 2 175 8
    and types are:
    <class ‘int’> <class ‘int’> <class ‘int’>

Recently Trained Students

Jessica Biel

– Infosys

My instructor had sound Knowledge and used to puts a lot of effort that made the course as simple and easy as possible. I was aiming for with the help of the ZebLearn Online training imparted to me by this organization.

Richard Harris

– ITC

I got my training from Zeblearn in the Python Certification Training, I would like to say that say he is one of the best trainers. He has not even trained me but also motivated me to explore more and the way he executed the project, in the end, was mind-blowing.


Candidate’s Journey During Our Training Program

Card image cap

Expert’s Advice & Selection of Module

Choosing the right type of module for the training is half the battle & Our Team of experts will help & guide you.

Card image cap

Get Trained

Get Trained & Learn End to End Implementation from our Expert Trainer who are working on the same domain.

Card image cap

Work on Projects

We Do make our student’s work on multiple case studies , scenario based tasks & projects in order to provide real-time exposure to them.

Card image cap

Placements

We have a dedicated placement cell in order to provide placement assistance & relevant interviews to our candididates till selection

Placement Partner

×

Leave your details

×

Download Course Content