In Python Programming , there is no need to specify a type on to a variable , it is done automatically. But if you want to specify type of a variable , then it can be done with Type Casting.

Python Type Casting

Python Type Casting is done using these functions:

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

Let’s understand this with an Example :-

Integer –

x = int(10) 
y = int(10.5) 
z = int("10")

All the above variables will result in int data type.

Float –

x = float(10)
y = float(10.5)
z = float("10")

All the above variables will result in float data type.

Strings –

x = str(10)
y = str(10.5)
z = str("10")

All the above variables will result in str data type.

Leave a Reply

Your email address will not be published.