Skip to main content

Command Palette

Search for a command to run...

Type Casting Techniques in Python

Published
1 min readView as Markdown

The purpose of Type Casting Techniques is in python is that "To Convert one Type of value into Another Possible Type of value".

in python programming we have 5 fundamentals Type Casting Techniques They are:

1.int()

2.float()

3.bool()

4.complex()

5.str()

1.int(): int() is used for converting possible Type of value into int type value.

Synatx: varname=int(float/complex/bool/str)

ex: float type into int type:

a=12.34

print(a,type(a)) ------>12.34 <class 'float'>

b=int(a)

print(a,type(a)) ----->12 <class 'int'>

ex2: bool type into int type:

a=True

print(a,type(a)) ----->True <class 'bool'>

b=False

print(b,type(b)) ----->False <class 'bool'>

c=int(a)

print(c,type(c))-----> 1 <class 'int'>

d=int(b)

print(d,type(d))-----> 0 <class 'int'>