473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Simple question on Python augumented assignment operators

I was browsing through some code and came across two operators I had never seen before. They were "+=" and "-=." I was just wondering what these were.

Thanks,
Jordan
Jul 16 '07 #1
3 1101
bvdet
2,851 Expert Mod 2GB
I was browsing through some code and came across two operators I had never seen before. They were "+=" and "-=." I was just wondering what these were.

Thanks,
Jordan
These are '-in-place' operators, also known as 'augumented assignment'. Example:
Expand|Select|Wrap|Line Numbers
  1. >>> a = 12
  2. >>> a += 12
  3. >>> a
  4. 24
  5. >>> a -=10
  6. >>> a
  7. 14
  8. >>> 
Jul 16 '07 #2
These are '-in-place' operators, also known as 'augumented assignment'. Example:
Expand|Select|Wrap|Line Numbers
  1. >>> a = 12
  2. >>> a += 12
  3. >>> a
  4. 24
  5. >>> a -=10
  6. >>> a
  7. 14
  8. >>> 
is it possible to also do *= /= or even **=?
Jul 16 '07 #3
bvdet
2,851 Expert Mod 2GB
is it possible to also do *= /= or even **=?
Expand|Select|Wrap|Line Numbers
  1. >>> a
  2. 14
  3. >>> a *= 2
  4. >>> a
  5. 28
  6. >>> a /= 2
  7. >>> a
  8. 14
  9. >>> a **= 2
  10. >>> a
  11. 196
  12. >>> 
Jul 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

134
by: Joseph Garvin | last post by:
As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very...
10
by: Andrew Koenig | last post by:
It has been pointed out to me that various C++ books disagree about the relative precedence of ?: and the assignment operators. In order to satisfy myself about the matter once and for all, I...
9
by: Rick N. Backer | last post by:
I have an abstract base class that has char* members. Is an assignment operator necessary for this abstract base class? Why or why not? Thanks in advance. Ken Wilson Amer. Dlx. Tele,...
11
by: jbperez808 | last post by:
>>> rs='AUGCUAGACGUGGAGUAG' >>> rs='GAG' Traceback (most recent call last): File "<pyshell#119>", line 1, in ? rs='GAG' TypeError: object doesn't support slice assignment You can't assign to...
19
by: fyhuang | last post by:
Hello all, I've been wondering a lot about why Python handles classes and OOP the way it does. From what I understand, there is no concept of class encapsulation in Python, i.e. no such thing as...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
16
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
0
by: Terry Reedy | last post by:
Arash Arfaee wrote: Python does not have 'in-place operators'. It has 'augmented assignment statements' that combines a binary operation with an assignment. *If* the target being rebound is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.