File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Python Built-in Data Types
2+
3+ In programming, data types are crucial because they define the kind of data a variable can store and how it can be used. Python has several built-in data types that are categorized as follows:
4+
5+ ## Text Type
6+ - ** ` str ` ** : Represents a string of characters.
7+
8+ ## Numeric Types
9+ - ** ` int ` ** : Represents integer numbers.
10+ - ** ` float ` ** : Represents floating-point numbers (decimals).
11+ - ** ` complex ` ** : Represents complex numbers (numbers with a real and imaginary part).
12+
13+ ## Sequence Types
14+ - ** ` list ` ** : An ordered, mutable collection of items.
15+ - ** ` tuple ` ** : An ordered, immutable collection of items.
16+ - ** ` range ` ** : Represents a sequence of numbers, often used in loops.
17+
18+ ## Mapping Type
19+ - ** ` dict ` ** : A collection of key-value pairs (dictionary).
20+
21+ ## Set Types
22+ - ** ` set ` ** : An unordered collection of unique items.
23+ - ** ` frozenset ` ** : An immutable version of a set.
24+
25+ ## Boolean Type
26+ - ** ` bool ` ** : Represents boolean values ` True ` or ` False ` .
27+
28+ ## Binary Types
29+ - ** ` bytes ` ** : Immutable sequence of bytes.
30+ - ** ` bytearray ` ** : Mutable sequence of bytes.
31+ - ** ` memoryview ` ** : A view object that exposes an array's buffer interface.
32+
33+ ## None Type
34+ - ** ` NoneType ` ** : Represents the absence of a value or a null value.
35+
36+ ## Getting the Data Type
37+
38+ You can find out the data type of any object by using the ` type() ` function:
39+
40+ ``` python
41+ x = 5
42+ print (type (x)) # Output: <class 'int'>
Original file line number Diff line number Diff line change 1+ a = 10
2+ print (a ) #10
3+ print (type (a )) #int
4+
5+ b = 10.0
6+ print (a ) #10.0
7+ print (type (a )) #float
8+
9+ c = "Fahad Ahmed"
10+ print (a ) #Fahad Ahmed
11+ print (type (a )) #String
12+
13+ a = True
14+ print (a ) #True
15+ print (type (a )) #Bool
16+
You can’t perform that action at this time.
0 commit comments