Questions and Answers Already Passed
What is a variable in programming?
✔✔A placeholder used to store a value
What is the result of the following Python expression:
`3 + 4 * 2`
✔✔11
What is the result of the following Python code:
```
if 5 > 3:
print("True")
else:
print("False")
```
✔✔True
1
,What is a dictionary in Python?
✔✔A collection of key-value pairs
What is the result of accessing a non-existing key in a dictionary?
✔✔It raises a `KeyError`
How do you add a key-value pair to a dictionary in Python?
✔✔By using the key inside square brackets and assigning a value to it
What is the purpose of a `while` loop in Python?
✔✔To repeat a block of code as long as a condition is true
What is the result of the following Python code:
```
x=5
while x > 0:
print(x)
x -= 1
2
,```
✔✔5 4 3 2 1
How do you check if a value exists in a list in Python?
✔✔By using the `in` keyword
What is the difference between `==` and `=` in Python?
✔✔`==` is used to check equality, while `=` is used for assignment
How do you get the length of a list in Python?
✔✔By using the `len()` function
What is the result of the following Python code:
```
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
```
3
, ✔✔[1, 2, 3, 4]
What is the purpose of a `break` statement in Python?
✔✔To exit a loop prematurely
What is the purpose of the `continue` statement in Python?
✔✔To skip the current iteration of a loop and move to the next one
What is the purpose of the `def` keyword in Python?
✔✔To define a function
How do you define a class in Python?
✔✔By using the `class` keyword followed by the class name
What is the purpose of the `__init__()` method in Python?
✔✔To initialize an object when it is created
How do you create an instance of a class in Python?
4