Hi there, we’re Harisystems

"Unlock your potential and soar to new heights with our exclusive online courses! Ignite your passion, acquire valuable skills, and embrace limitless possibilities. Don't miss out on our limited-time sale - invest in yourself today and embark on a journey of personal and professional growth. Enroll now and shape your future with knowledge that lasts a lifetime!".

For corporate trainings, projects, and real world experience reach us. We believe that education should be accessible to all, regardless of geographical location or background.

1
1

Python Type Casting

Type casting, also known as type conversion, is the process of changing the data type of a value or variable from one type to another. Python provides built-in functions for performing type casting operations. Let's explore some common type casting functions and examples.

1. int()

The int() function is used to convert a value or variable to an integer data type.

Example:

    x = 5.7
y = int(x)
  

In the above example, the value of x is initially a float. By using the int() function, we cast it to an integer and assign the result to the variable y. The value of y will be 5.

2. float()

The float() function is used to convert a value or variable to a float data type.

Example:

    x = 10
y = float(x)
  

In the above example, the value of x is initially an integer. By using the float() function, we cast it to a float and assign the result to the variable y. The value of y will be 10.0.

3. str()

The str() function is used to convert a value or variable to a string data type.

Example:

    x = 100
y = str(x)
  

In the above example, the value of x is initially an integer. By using the str() function, we cast it to a string and assign the result to the variable y. The value of y will be "100".

4. bool()

The bool() function is used to convert a value or variable to a boolean data type.

Example:

    x = 0
y = bool(x)
  

In the above example, the value of x is initially an integer. By using the bool() function, we cast it to a boolean and assign the result to the variable y. The value of y will be False since the integer value 0 is considered as False in boolean context.

Conclusion

Type casting allows you to convert values or variables from one data type to another in Python. By utilizing the appropriate type casting functions, you can ensure data compatibility and perform necessary operations on different data types.

4.5L

Learners

20+

Instructors

50+

Courses

6.0L

Course enrollments

4.5/5.0 5(Based on 4265 ratings)

Future Trending Courses

When selecting, a course, Here are a few areas that are expected to be in demand in the future:.

Beginner

The Python Course: Absolute Beginners for strong Fundamentals

By: Sekhar Metla
4.5 (13,245)
Intermediate

JavaScript Masterclass for Beginner to Expert: Bootcamp

By: Sekhar Metla
4.5 (9,300)
Intermediate

Python Coding Intermediate: OOPs, Classes, and Methods

By: Sekhar Metla
(11,145)
Intermediate

Microsoft: SQL Server Bootcamp 2023: Go from Zero to Hero

By: Sekhar Metla
4.5 (7,700)
Excel course

Future Learning for all

If you’re passionate and ready to dive in, we’d love to join 1:1 classes for you. We’re committed to support our learners and professionals their development and well-being.

View Courses

Most Popular Course topics

These are the most popular course topics among Software Courses for learners