Oct. 16, 2015

Numeric Types in Python

In any OOP language, there are many different data types. In Python, number data types are used to store numeric values. There are four different numerical types in Python:
  1. int (plain integers): this one is pretty standard -- plain integers are just positive or negative whole numbers.
  2. long (long integers): long integers are integers of infinite size. They look just like plain integers except they're followed by the letter "L" (ex: 150L).
  3. float (floating point real values): floats represent real numbers, but are written with decimal points (or scientific notaion) to divide the whole number into fractional parts. 
  4. complex (complex numbers): represented by the formula a + bJ, where a and b are floats, and J is the square root of -1 (the result of which is an imaginary number). Complex numbers are used sparingly in Python. 
 
Applying the function call operator () to a numeric type creates an instance of that type. For example: calling int(x) will convert x to a plain integer. This can also be used with the long, float, and complex types. 

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.

 



Read more about:
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, PythonForBeginners.com only recommend products or services that we try personally and believe will add value to our readers.