Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / ^=, -= and += symbols in Python

^=, -= and += symbols in Python

October 8, 2021 by James Palmer

As almost any modern language, python has Assignment Operators
so they can use them every time you want to assign a value to a variable after doing some arithmetic or logical operation, both (assignment and operation)are expressed compact way in one statement….

When you compute X = X + Y you are actually returning the sum of X and Y into a new variable, which, in your example, overwrites the previous value of X. When you use an assignment operator in the form of X += 1, the value 1 is directly summed on the current value of X, without returning the result in a new variable. Take a look at the code below:
>>> V = np.arange(10)
>>> view = V[3:] # view is just a subspace (reference) of the V array
>>> print(V);print(view)
[0 1 2 3 4 5 6 7 8 9]
[3 4 5 6 7 8 9]
>>> view = view + 3 # add view to a constant in a new variable
>>> print(V);print(view)
[0 1 2 3 4 5 6 7 8 9]
[ 6 7 8 9 10 11 12]
>>> view = V[3:]
>>> view += 3 # here you actually modify the value of V
>>> print(V);print(view)
[ 0 1 2 6 7 8 9 10 11 12]
[ 6 7 8 9 10 11 12]

You can also look for the documentation of numpy.ndarray.base to check if an array is actually a reference of another array.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2023 · News Pro Theme on Genesis Framework · WordPress · Log in