There are mainly three data types, namely:

int

float

string

Let's see an example of all of them in this small program:

a = raw_input("Enter a: ") # Taking input for first num in string form

b = raw_input("Enter b: ") # Taking input for second num string form

print "a + b as strings: %s" % a + b # + will concate and will show in string

a = int(a) # Converting in to integer

b = int(b) # Converting in to integer

c = a + b # Adding two integer

print "a + b as integers: %d" % c # Printing two integer

a = float(a) # Converting in to float

b = float(b) # Converting in to float

d = a/b # deriding

print "a / b as float : %f" % d # printing as float

Enter a: 100

Enter b: 35

a + b as strings: 10035

a + b as integers: 135

a / b as float : 2.857143

int

float

string

Let's see an example of all of them in this small program:

b = raw_input("Enter b: ") # Taking input for second num string form

print "a + b as strings: %s" % a + b # + will concate and will show in string

a = int(a) # Converting in to integer

b = int(b) # Converting in to integer

c = a + b # Adding two integer

print "a + b as integers: %d" % c # Printing two integer

a = float(a) # Converting in to float

b = float(b) # Converting in to float

d = a/b # deriding

print "a / b as float : %f" % d # printing as float

**Output:**Enter a: 100

Enter b: 35

a + b as strings: 10035

a + b as integers: 135

a / b as float : 2.857143

## No comments:

## Post a Comment