Python Types

Learn about the basic data types and variable assignment in Python.

Python supports three categories of data types:

  • Basic types: int, float, complex, bool, str, bytes
  • Container types: list, tuple, set, dictionary
  • User-defined types: class

Basic types

Here are some examples of different basic types:

  • int: It can be expressed in binary, decimal, octal or hexadecimal. Binary starts with 0b/0B, octal with 0o/0O and hex with 0x/0X, e.g., 0b10111, 156, 0o432, 0x4A3 etc.

  • float: It can be expressed in a fractional or exponential form, e.g., 314.1528, 3.1415282^{2}, 3.1415282^{2}, etc.

  • complex: It contains real and imaginary parts, e.g., 3 + 2j, 1 + 4j, etc.

  • bool: It can take any of the two boolean values, both starting in caps: True, False

  • str: It is an immutable collection of Unicode characters enclosed within ' ', " " or """ """, e.g., 'Razzmatazz', "Razzmatazz", """Razzmatazz""".

  • bytes: It represents binary data.

The type of particular data can be checked using a function called type(), as shown below:

Get hands-on with 1200+ tech skills courses.