Type | Example | Description |
---|---|---|
int |
x = 1 |
integers (i.e., whole numbers) |
float |
x = 1.0 |
floating-point numbers (i.e., real numbers) |
complex |
x = 1 + 2j |
Complex numbers (i.e., numbers with real and imaginary part) |
bool |
x = True |
Boolean: True/False values |
str |
x = 'abc' |
String: characters or text |
NoneType |
x = None |
Special object indicating nulls |
can be defined either in standard decimal notation, or in exponential notation
1.06 or 106e-2 e or E.
float
constructor:float(1)
None-Type has only a single possible value: None.
None
is used in many places, most commonly as the default return
value of a function.
Es any function in Python with no return value is, in reality, returning
None
.
None
frequently used
to represent the absence of a value.
built-in_constants
isinstance(x, type(None)) equi x is None
ref: realpython/null-in-python
bool()
object constructor constructs a boolean valuevalues of any other type can be converted to Boolean via predictable rules.
Es numeric type is False if equal to zero, and True otherwise:
bool(2014) >>> True
bool(0) >>> False
For strings, bool(s)
is False for empty strings and True
otherwise.
Called after the instance has been created (by __new__()), but before it is returned to the caller. The arguments are those passed to the class constructor expression.
A dictionary or other mapping object used to store an object’s (writable) attributes.
Called by the repr() built-in function to compute the “official” string representation of an object.