|
| 1 | +--- |
| 2 | +title: Data Types in Python |
| 3 | +sidebar_label: Data Types |
| 4 | +--- |
| 5 | + |
| 6 | +# Data Types in Python |
| 7 | + |
| 8 | +<SubHeading>Learn more about Data Types in Python (with Samples)</SubHeading> |
| 9 | + |
| 10 | +Python supports various data types that allow you to work with different kinds of data. |
| 11 | + |
| 12 | +Here's an overview of **common data types in Python**: |
| 13 | + |
| 14 | +## ✅ **Numeric Data Types** |
| 15 | + |
| 16 | +- **int**: Represents integers, e.g., `5`, `-10`, `1000`. |
| 17 | +- **float**: Represents floating-point numbers (real numbers), e.g., `3.14`, `0.001`, `2.0`. |
| 18 | +- **complex**: Represents complex numbers, e.g., `3 + 4j`, where `3` is the real part and `4` is the imaginary part. |
| 19 | + |
| 20 | +## ✅ **Text Data Type** |
| 21 | + |
| 22 | +- **str**: Represents strings of text, e.g., `"Hello, World"`, `'Python'`, `"123"`. |
| 23 | + |
| 24 | +## ✅ **Boolean Data Type** |
| 25 | + |
| 26 | +- **bool**: Represents boolean values, either `True` or `False`. Used for logical operations and control flow. |
| 27 | + |
| 28 | +## ✅ **Sequence Types** |
| 29 | + |
| 30 | +- **list**: Ordered, mutable sequences of elements, e.g., `[1, 2, 3]`, `['apple', 'banana', 'cherry']`. |
| 31 | +- **tuple**: Ordered, immutable sequences, e.g., `(1, 2, 3)`, `('red', 'green', 'blue')`. |
| 32 | +- **range**: Represents a sequence of numbers, often used in loops, e.g., `range(5)` produces `0, 1, 2, 3, 4`. |
| 33 | + |
| 34 | +## ✅ **Mapping Type** |
| 35 | + |
| 36 | +- **dict**: Represents dictionaries, which are collections of key-value pairs, e.g., `{'name': 'Alice', 'age': 30}`. |
| 37 | + |
| 38 | +## ✅ **Set Types** |
| 39 | + |
| 40 | +- **set**: Represents an unordered collection of unique elements, e.g., `{1, 2, 3}`. |
| 41 | +- **frozenset**: Similar to a set but is immutable. |
| 42 | + |
| 43 | +## ✅ **Binary Data Types** |
| 44 | + |
| 45 | +- **bytes**: Represents sequences of bytes, e.g., `b'hello'`. |
| 46 | +- **bytearray**: Mutable sequences of bytes. |
| 47 | + |
| 48 | +## ✅ **None Type** |
| 49 | + |
| 50 | +- **None**: Represents the absence of a value or a null value. |
| 51 | + |
| 52 | +## ✅ **Custom Classes** |
| 53 | + |
| 54 | +You can define your own classes and create custom data types in Python. |
| 55 | + |
| 56 | + |
| 57 | +These are the fundamental data types in Python. You can perform various operations and manipulations on these data types to process and manipulate data in your Python programs. |
| 58 | + |
| 59 | +## ✅ **Coding Sample** |
| 60 | + |
| 61 | +Here's a quick example: |
| 62 | + |
| 63 | +```python |
| 64 | +# Numeric data types |
| 65 | +age = 30 |
| 66 | +height = 5.9 |
| 67 | +complex_num = 3 + 4j |
| 68 | + |
| 69 | +# Text data type |
| 70 | +name = "Alice" |
| 71 | + |
| 72 | +# Boolean data type |
| 73 | +is_student = True |
| 74 | + |
| 75 | +# Lists |
| 76 | +fruits = ['apple', 'banana', 'cherry'] |
| 77 | + |
| 78 | +# Dictionary |
| 79 | +person = {'name': 'John', 'age': 25} |
| 80 | + |
| 81 | +# Sets |
| 82 | +unique_numbers = {1, 2, 3} |
| 83 | + |
| 84 | +# None type |
| 85 | +no_value = None |
| 86 | +``` |
| 87 | + |
| 88 | +## ✅ In Summary |
| 89 | + |
| 90 | +Understanding these data types is fundamental to writing Python code and performing various operations on data in Python. |
| 91 | + |
| 92 | +## ✅ Resources |
| 93 | + |
| 94 | +- 👉 Access [AppSeed](https://appseed.us/) for more starters and support |
| 95 | +- 👉 [Deploy Projects on Aws, Azure and DO](https://www.docs.deploypro.dev/) via **DeployPRO** |
| 96 | +- 👉 Create landing pages with [Simpllo, an open-source site builder](https://www.simpllo.com/) |
| 97 | +- 👉 Build apps with [Django App Generator](https://app-generator.dev/django/) (free service) |
0 commit comments