0

Python's system of deciding for you what type to give all your variables is nice and all, but is there a way to force it to give a variable a certain data type? For instance, if you give it the following:

n = 2
m = 3
print n/m

It'll print out 0, because all the variables are ints, and it truncates the fraction off. Any way to get around this?

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by vegaseat
0
n = float(2)
m = float(3)
print n/m

Or

n = 2.0
m = 3.0
print n/m

Hope that helps.

0

Actually, the next version of Python (3.0) will use '/' for floating point divisions and '//' for integer divisions.

Pascal for instance has '/' for floating point divisions and 'div' for integer divisions since inception 30+ years ago.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.