Assigning Values

1 minutes
Share the link to this page
Copied
  Completed

The operators that are used in Python programming to assign values are listed in the presentation of this lecture. All except the simple = assignment operator are a shorthand form  of a longer expression, so each equivalent is given for clarity:

The += operator is useful to add value onto an existing value that is stored in a variable.

In the table example, the += operator first adds the value contained in variable a to the value contained in variable b. It then assigns the result to become the new value stored in variable a.

All the other operators work in the same way by making the arithmetical operation between the two values first, then assigning the result of that operation to the first variable – to become its new stored value.

With the %= operator, the first operand a is divided by the second operand b, then the remainder of that operation is assigned to a variable.

  Download

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.