Skip to content

Commit 821139c

Browse files
committed
Enhance data types section with detailed descriptions and examples
1 parent 43b511f commit 821139c

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

docs/cheatsheet/basics.md

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,51 @@ The _Walrus Operator_, or **Assignment Expression Operator** was firstly introdu
116116

117117
## Data Types
118118

119-
| Data Type | Examples |
120-
| ---------------------- | ----------------------------------------- |
121-
| Integers | `-2, -1, 0, 1, 2, 3, 4, 5` |
122-
| Floating-point numbers | `-1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25` |
123-
| Strings | `'a', 'aa', 'aaa', 'Hello!', '11 cats'` |
119+
Python has nine core built-in data types that cover almost everything you'll need:
120+
121+
| Data Type | Examples | Description |
122+
| ---------------------------------------------------------- | ---------------------------------------- | ------------------------------------- |
123+
| **Numbers** | | |
124+
| <router-link to='/builtin/int'>`int`</router-link> | `-2, -1, 0, 1, 2, 3, 4, 5` | Whole numbers (integers) |
125+
| <router-link to='/builtin/float'>`float`</router-link> | `-1.25, -1.0, -0.5, 0.0, 0.5, 1.0, 1.25` | Numbers with decimal points |
126+
| <router-link to='/builtin/complex'>`complex`</router-link> | `2+3j, complex(1, 4)` | Numbers with real and imaginary parts |
127+
| **Text** | | |
128+
| <router-link to='/builtin/str'>`str`</router-link> | `'a', 'Hello!', "Python"` | Text and characters |
129+
| **Boolean** | | |
130+
| <router-link to='/builtin/bool'>`bool`</router-link> | `True, False` | True or False values |
131+
| **None** | | |
132+
| `NoneType` | `None` | Represents "no value" or "nothing" |
133+
| **Collections** | | |
134+
| <router-link to='/builtin/list'>`list`</router-link> | `[1, 2, 3], ['a', 'b', 'c']` | Ordered, changeable collections |
135+
| <router-link to='/builtin/dict'>`dict`</router-link> | `{'name': 'Alice', 'age': 30}` | Key-value pairs |
136+
| <router-link to='/builtin/tuple'>`tuple`</router-link> | `(1, 2, 3), ('a', 'b')` | Ordered, unchangeable collections |
137+
| <router-link to='/builtin/set'>`set`</router-link> | `{1, 2, 3}, {'a', 'b', 'c'}` | Unordered collections of unique items |
138+
139+
### Quick Examples
140+
141+
```python
142+
# Numbers
143+
age = 25 # int
144+
price = 19.99 # float
145+
coordinate = 2 + 3j # complex
146+
147+
# Text
148+
name = "Alice" # str
149+
150+
# Boolean
151+
is_student = True # bool
152+
153+
# None
154+
result = None # NoneType
155+
156+
# Collections
157+
scores = [85, 92, 78] # list
158+
person = {'name': 'Bob', 'age': 30} # dict
159+
coordinates = (10, 20) # tuple
160+
unique_ids = {1, 2, 3} # set
161+
```
162+
163+
For a comprehensive guide with visual examples and detailed explanations of when to use each type, see: <router-link to="/blog/python-data-types">Python Data Types: A Visual Guide for Beginners</router-link>.
124164

125165
## Concatenation and Replication
126166

@@ -278,7 +318,6 @@ It is also possible to use formatted strings to avoid using .format:
278318
# Hi, Martha
279319
```
280320

281-
282321
## The len() Function
283322

284323
Evaluates to the integer value of the number of characters in a string, list, dictionary, etc.:

0 commit comments

Comments
 (0)