Python Types
Explore Python's data types including integers, floats, complex numbers, booleans, strings, and containers like lists and dictionaries. Understand dynamic typing, variable assignment, and how to inspect data types using the type() function for better coding practices.
We'll cover the following...
We'll cover the following...
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 with0b/0B, octal with0o/0Oand hex with0x/0X, e.g., 0b10111, 156, 0o432, 0x4A3 etc. -
float: It can be expressed in a fractional or exponential form, e.g., 314.1528, 3.141528 ...