mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(curriculum): corrected dict() example value types (#65255)
This commit is contained in:
+10
-10
@@ -55,46 +55,46 @@ To create a Python dictionary, you just need to write the key-value pairs within
|
||||
|
||||
```python
|
||||
my_dictionary = {
|
||||
"A": 1,
|
||||
"B": 2,
|
||||
"C": 3
|
||||
'A': 1,
|
||||
'B': 2,
|
||||
'C': 3
|
||||
}
|
||||
```
|
||||
|
||||
In this code, `"A"` is the key and `1` is the value:
|
||||
In this code, `'A'` is the key and `1` is the value:
|
||||
|
||||
```python
|
||||
"A": 1
|
||||
'A': 1
|
||||
```
|
||||
|
||||
Alternatively, you can use `dict()`:
|
||||
|
||||
```python
|
||||
my_dictionary = dict(A="1", B="2", C="3")
|
||||
my_dictionary = dict(A=1, B=2, C=3)
|
||||
```
|
||||
|
||||
You can get the value through its corresponding key:
|
||||
|
||||
```python
|
||||
my_dictionary["A"] # 1
|
||||
my_dictionary['A'] # 1
|
||||
```
|
||||
|
||||
You can also update the value associated with a key:
|
||||
|
||||
```python
|
||||
my_dictionary["A"] = 4
|
||||
my_dictionary['A'] = 4
|
||||
```
|
||||
|
||||
And you can remove a key-value pair:
|
||||
|
||||
```python
|
||||
del my_dictionary["A"]
|
||||
del my_dictionary['A']
|
||||
```
|
||||
|
||||
You can also check if a key is in the dictionary (or not):
|
||||
|
||||
```python
|
||||
"C" in my_dictionary
|
||||
'C' in my_dictionary
|
||||
```
|
||||
|
||||
And you can call these methods to get the keys, values, and items of the dictionary, respectively.
|
||||
|
||||
Reference in New Issue
Block a user