Recall & Review
beginner
What is the purpose of the assignment operator
= in Python?The assignment operator
= is used to store a value in a variable. It assigns the value on the right to the variable on the left.Click to reveal answer
beginner
What does the augmented assignment operator
+= do?The
+= operator adds the value on the right to the variable on the left and then updates the variable with the new value. For example, x += 3 means x = x + 3.Click to reveal answer
beginner
List three common augmented assignment operators in Python.
Three common augmented assignment operators are:<br>1.
+= (add and assign)<br>2. -= (subtract and assign)<br>3. *= (multiply and assign)Click to reveal answer
beginner
What happens if you use
x *= 2 when x is 5?The value of
x becomes 10 because x *= 2 means x = x * 2. So, 5 multiplied by 2 equals 10.Click to reveal answer
beginner
Can augmented assignment operators be used with strings? Give an example.
Yes, augmented assignment operators like
+= can be used with strings to concatenate them. For example:<br>text = 'Hello'<br>text += ' World'<br>Now, text is 'Hello World'.Click to reveal answer
What does the statement
count -= 1 do?✗ Incorrect
The operator
-= subtracts the value on the right (1) from the variable on the left (count).Which of the following is equivalent to
x += 5?✗ Incorrect
x += 5 means add 5 to x and assign the result back to x, which is x = x + 5.What will be the value of
text after this code?<br>text = 'Hi'<br>text += ' there'✗ Incorrect
The
+= operator concatenates the string ' there' to 'Hi', resulting in 'Hi there'.If
num = 10, what does num *= 3 do?✗ Incorrect
num *= 3 multiplies num by 3 and assigns the result back to num, so num becomes 30.Which operator would you use to divide a variable by 4 and update it with the result?
✗ Incorrect
The
/= operator divides the variable by the value on the right and updates it.Explain how assignment and augmented assignment operators work in Python with examples.
Think about how you store and update values in a variable.
You got /4 concepts.
Describe three different augmented assignment operators and what they do.
Focus on the operation and assignment combined.
You got /4 concepts.