26.6. Data Types and Variables

Python uses dynamic data typing. This means that the Python compiler doesn't assign a type to the objects that it uses. The virtual machine instead does the assignment at run-time. This adds a great deal of flexibility to Python, but it can also create errors that are difficult to find. For example, if a typographical error is made when typing the variable name, it will be recognized as a new variable, which may not be immediately obvious to the person executing the code.

26.6.1. Data Types

Python supports the following five types of data:

  • Numbers

  • Strings

  • Lists

  • Dictionaries

  • Tuples

26.6.1.1. Numbers

Python supports four numerical types:

  • int (signed integers)—Most 32-bit computers will offer an integer range from −231 to 231-1 (−2,147,483,648 to 2,147,483,647).

  • long (long integers)—The range of Python longs are limited only by the amount of virtual memory a system has. Longs may be represented in decimal, octal, or hexadecimal notation. As in most other languages, long integers in decimal form are denoted by an uppercase L or a lowercase l. Some examples follow:

    • 99999999999L

    • −23456l

    • 0xD34F867CA0

  • float (floating-point real values)—Floating-point numbers in Python are denoted by a decimal point and either a lowercase e or an uppercase E and a positive (+) or negative (-) sign. Examples follow:

    • 0.99

    • −953.234

    • 96.7e3

    • −1.609E-19

  • complex (complex numbers)—Complex numbers have real and imaginary components. Complex number attributes are accessible like this:

    >>>myComplex ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.