According to Data Science Topic-8 Type conversion

 # Explicit

# str -> int

int('4')

4

type(int('4'))

int

type(int('4.5')

4

int(4+5j)

error

# int to str

str(5)

5

# float

float(4)

4.0

fnum = input('Enter first number')


snum = input('Enter second number')


print(type(fnum), type(snum))


print(fnum,snum)


    # add 2 variables


result = int(fnum) + int(snum)


print(result)

print(type(fnum))

Output: Enter first number56

Enter second number67

<class 'str'> <class 'str'>

56 67

123

when we want to know the data type of a function then we will know the result is a string because the original data type has not changed in Python type conversion.

fnum = int(input('Enter first number'))


snum = int(input('Enter second number'))


print(type(fnum), type(snum))


print(fnum,snum)


    # add 2 variables


result = int(fnum) + int(snum)


print(result)

Output: Enter first number56

Enter second number67

<class 'int'>

123




Comments

Popular posts from this blog

According to Data Science Topic-13 Modules

Functions in Python:

According to Data Science Topic-12 If else program examples