Python Questions and Answers 100%
Pass
What is the output of the following code?
```python
person = {"name": "Alice", "age": 25}
print(person["name"])
```
✔✔ The output will be `Alice` because the value associated with the key `"name"` is `"Alice"`.
What is the output of the following code?
```python
for i in range(3):
print(i)
```
✔✔ The output will be `0`, `1`, `2` because `range(3)` generates numbers from `0` to `2`.
1
,How do you update the value of a key in a dictionary?
✔✔ You can update the value of a key in a dictionary by assigning a new value to the key, like
`dictionary[key] = new_value`.
What is the output of the following code?
```python
person = {"name": "Alice", "age": 25}
person["age"] = 26
print(person)
```
✔✔ The output will be `{'name': 'Alice', 'age': 26}` because the value of `"age"` is updated to
`26`.
How do you access the values in a dictionary?
✔✔ You can access the values in a dictionary by using the keys, like `dictionary[key]`.
2
, What is the output of the following code?
```python
person = {"name": "Alice", "age": 25}
print(person["age"])
```
✔✔ The output will be `25` because the value associated with the key `"age"` is `25`.
What is the purpose of the `print()` function in Python?
✔✔ The `print()` function is used to display messages or variables in the console.
How do you define a variable in Python?
✔✔ A variable is defined by assigning a value to a name, like `variable_name = value`.
What is the difference between integers and floats in Python?
✔✔ Integers are whole numbers without decimal points, while floats are numbers that include
decimal points.
3