Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to implement type conversion in python?

Description

To see how type casting has been implemented in python3.

Process
Implicit Type Conversion

   Python automatically converts one data type to another data type.

   This process doesn't need any user involvement.

Explicit Type Conversion

   In Explicit type conversion, users need to convert the data type of an object to required data type.

   We can use the predefined functions like int(), float(), str(), etc to perform explicit type conversion

Sample Code

Source code(Implicit Type Conversion):

#Implicit Type Conversion
#Get an integer input
n=int(input(“Enter the integer:”))

#Get another float input
m=float(input(“Enter the number:”))

#add those inputs
o=n+m

#print the variable o
print(o)
#print type of variable o
print(type(o))

Source code(Explicit Type Conversion):

#Explicit Type Conversion
print(“###########################”)
print(“Explicit Type conversion”)
n=int(input(“Enter the integer:”))
m=input(“Enter the number:”)
print(“\n”)
print(“Data type of m(before conversion) is:”,type(m))
print(“\n”)

#Explicit type conversion
m=int(m)
print(“Data type of m(after conversion) is:”,type(m))

#add those inputs
o=n+m

#print the variable o
print(o)

#print type of variable o
print(type(o))

Screenshots
implement type conversion in python
type casting has been implemented in python3