Compound multiplication #
Compound multiplication is a shorthand way of multiplying a variable by a given value and then assigning the result to the same variable. It uses the *= operator.
For example:
x = 5
x *= 2 # equivalent to x = x * 2
print(x) # Output: 10
Exercise #
- Rewrite the code on line 3 to use
*=to multiply the value ofxand assign it back to the variablex - Value of
xshould be100
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules