the types of numbers available in python
depend on which version you are using
if you are using version 2 there are
four types of numbers if you are using
version 3 there are three types of
numbers
if you are using version 4 you're living
in the future and i hope it's amazing
our goal today learn about the types of
numbers in python version 2.
first start the python interpreter
if you see version 3 be sure to watch
our video on numbers for version 3.
this video is for people using version 2
and some of the examples will cause an
error if you use python 3.
in python version 2 there are four types
of numbers inc's longs floats and
complex numbers
two of these types are for whole numbers
inc which is short for integer and longs
which one you use depends on how large
the whole number is
most of the time you'll use ins but if
your number gets too large python will
automatically switch to longs for you
notice the hashtag this is how you write
comments in python
everything after a hashtag is a comment
and is ignored by the interpreter
let's assign the number 28 to the
variable a
you can see what data type this is by
using the type function
a is an int not a long
if you ever need to see the value of a
just type it and press enter this will
print the number
and if you love typing you can
explicitly print it
ins let you store whole numbers up to a
limit to find out the limit first import
the sys module
and then check the max end property
we'll talk all about imports and modules
soon
for now just remember that import sys
brings in a library of system functions
let's create an integer b with this
maximum value
you can see that it's an int
but watch what happens if we create the
next whole number we'll call it c
it creates a long
you can also tell this is a long by
displaying its value
see the l at the end
this is how python tells you the number
is a long and not an int
by the way if you print c the letter l
will not display
this is because printing displays more
human readable values
luckily you do not have to worry too
much about ins and longs if your integer
gets too large python switches over to
longs
you don't have to worry about integer
overflow in python
for the curious the smallest int in
python version 2 is equal to minus sys
dot maxint minus one
you can verify this as an int by
checking its type
or by displaying its value and observing
there is no l at the end
if you subtract one from this whole
number then you will see that python
uses a long
when creating a whole number you can
specify if you'd like to use a long
to do so put a letter l at the end of
your number
but given python's automatic handling of
ins and longs this isn't something you
really need to worry about
the third type of number in python
version 2 is floats
this is how decimal values are stored to
make a float just type in a number that
has a decimal point
we'll use the famous number e which is
approximately 2.7 1828 1828
to confirm that this is a float look at
its type
the fourth and final type of number in
python version 2 is complex numbers
a complex number has a real part and an
imaginary part the mathematical symbol
for the complex numbers is a capital c
with an extra stroke
while the mathematical symbol for the
square root of -1 is i
many engineers will use the letter j
and this is what python uses
so to create a complex number just type
in the real part and then the imaginary
part followed by the letter j
you can confirm that this is a complex
number by checking its type
you can display its real part by
displaying the real property
and you can access the imaginary part
through the property named imag
python automatically uses floats for the
real and imaginary parts
now that you know about ins longs floats
and complex numbers you are ready to
tackle arithmetic
just remember i is called j
long's end in l and the only thing that
can overflow was your drink