What is Type Casting in python?

Conversion of one type of value in another type known as TYPE CASTING

Here the list of inbuilt function for type casting:

  1.  int()
  2. float()
  3. bool()
  4. str()

1.INT() →  used for changing value type in to INT data type

Example:

a = 1.5

print(type(a)) // INT

b = int(a)

print(type(b)) // float

print(b)

2.float() → used for changing value type in to FLOAT data type

Example :

a = 1

print(type(a))//float

b = float(a)

print(type(b))// INT

print(b)

3.bool() → used for changing value type in to BOOL data type

Example:

a = 1

b = 0

b = bool(a)

c = bool(b)

print(b)//True

print(c)//False

4.str() → used for changing value type in to str data type

please learn with us!!!

Leave a Reply

Your email address will not be published. Required fields are marked *