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.
1Python 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
Future Trending Courses
When selecting, a course, Here are a few areas that are expected to be in demand in the future:.
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 CoursesMost Popular Course topics
These are the most popular course topics among Software Courses for learners