File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ ## What are Types in Python?
2+
3+ Python code can be written using various built-in types that define their behavior and available operations:
4+
5+ - ** Numeric Types**
6+ - ` int ` : whole numbers (e.g. ` 5 ` , ` -100 ` )
7+ - ` float ` : decimal numbers (e.g. ` 3.14 ` , ` -0.5 ` )
8+ - ` complex ` : numbers with real & imaginary parts (e.g. ` 2 + 3j ` )
9+
10+ - ** Boolean**
11+ - ` bool ` : truth values, ` True ` or ` False `
12+
13+ - ** Text**
14+ - ` str ` : immutable sequences of characters (e.g. ` "hello" ` )
15+
16+ - ** Binary**
17+ - ` bytes ` : immutable byte sequences
18+ - ` bytearray ` : mutable byte sequences
19+ - ` memoryview ` : a view on another binary object
20+
21+ - ** Sequences**
22+ - ` list[T] ` : mutable, ordered collections (e.g. ` list[int] ` )
23+ - ` tuple[T1, T2, …] ` : immutable ordered collections (e.g. ` tuple[int, str] ` )
24+ - ` range ` : immutable sequences of integers, typically used in loops
25+
26+ - ** Mappings**
27+ - ` dict[K, V] ` : mutable key→value stores (e.g. ` dict[str, float] ` )
28+
29+ - ** Sets**
30+ - ` set[T] ` : mutable, unordered unique items
31+ - ` frozenset[T] ` : immutable sets of unique items
32+
33+ - ** None**
34+ - ` None ` : the singleton “no value” object (its type is ` NoneType ` ).
35+ > _ Note: ` print() ` always returns ` None ` . Functions return ` None ` unless an explicit ` return ` is provided._
36+
37+ ---
38+
39+ ### Example
40+
41+ x: int = 3
42+ y: float = 1.0
43+ frozen: bool = True
44+ name: str = "Rupert"
45+
You can’t perform that action at this time.
0 commit comments