0
0
Pythonprogramming~5 mins

Assignment and augmented assignment in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASubtracts 1 from count
BDivides count by 1
CMultiplies count by 1
DAdds 1 to count
Which of the following is equivalent to x += 5?
Ax = 5 + x
Bx = x - 5
Cx = 5 - x
Dx = x + 5
What will be the value of text after this code?<br>text = 'Hi'<br>text += ' there'
A'Hi there'
B'Hi+ there'
C'Hi'
D'there'
If num = 10, what does num *= 3 do?
ASets num to 13
BSets num to 30
CSets num to 7
DSets num to 3
Which operator would you use to divide a variable by 4 and update it with the result?
A+=
B*=
C/=
D-=
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.