Monday, December 11, 2017

Integers and Floats in Python

Defining integers in Python is very easy.
eg:
answer=42

pi=3.14159

Python 3 also introduces complex numbers as a type.There is no real need to worry about types in Python.atleast not in the beginning.

answer + pi = 45.14159 # Don't worry about conversion !

you can seamlessly add integers, float .pyhton does not complain about it.it will produce desired results.And to cast anything.just have to do something like this.

int(pi) == 3
float(answer) == 42.0

this is needed when we really want to cast the integer and float variables.

No comments: