Why does python create a reference here, not just copy the variable?
>>j=range(0,6) k=j del j[0] j
[1, 2, 3, 4, 5]
>>k
[1, 2, 3, 4, 5]
Shouldn't k remain the same?
--
Micha³ Bentkowski mr*****@gmail.com 4 1289
On Mar 26, 4:04 pm, "Micha³ Bentkowski" <mr.e...@gmail.comwrote:
Why does python create a reference here, not just copy the variable?
>j=range(0,6) k=j del j[0] j
[1, 2, 3, 4, 5]
>k
[1, 2, 3, 4, 5]
Shouldn't k remain the same?
http://www.effbot.org/zone/python-list.htm
Micha³ Bentkowski pisze:
Why does python create a reference here, not just copy the variable?
Because Python works like that -- it uses names and values idiom. If you
change value, all names will be bound to the same changed value.
>>>j=range(0,6) k=j del j[0] j
[1, 2, 3, 4, 5]
>>>k
[1, 2, 3, 4, 5]
Shouldn't k remain the same?
No further comments on this.
--
Jarek Zgoda http://zgodowie.org/
"We read Knuth so you don't have to" - Tim Peters
Micha³ Bentkowski:
Why does python create a reference here, not just copy the variable?
I think to increase performance, in memory used and running time (and
to have a very uniform way of managing objects).
Bye,
bearophile
On Mar 26, 5:28*pm, bearophileH...@lycos.com wrote:
Micha³ Bentkowski:
Why does python create a reference here, not just copy the variable?
I think to increase performance, in memory used and running time (and
to have a very uniform way of managing objects).
Bye,
bearophile
A variable is a name-value pair. It's undefined outside of one-to-
ones therein. You have two names. Do they refer to the same object.
There is no such thing as the "primitive contents" of -any- standard
object. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Christian Neumann |
last post by:
Hello,
i have a problem with the built-in function xrange(). Could you by any
chance be able to help?
I use Python 2.3.4 (final) and i think there is a bug in the built-in
|
by: Fred Pacquier |
last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been
able to phrase my questions well enough to get a meaningful answer from
Google in my research. OTOH, it is standard...
|
by: Andrew Dalke |
last post by:
Is there an author index for the new version of the
Python cookbook? As a contributor I got my comp version
delivered today and my ego wanted some gratification.
I couldn't find my entries.
...
|
by: Steven Bethard |
last post by:
George Sakkis wrote:
> "Steven Bethard" <steven.bethard@gmail.com> wrote:
>> Dict comprehensions were recently rejected:
>> http://www.python.org/peps/pep-0274.html
>> The reason, of course,...
|
by: Ryan |
last post by:
I have a dropdown list bound to a datasource. I would like to clear it
at the press of a button. I tried using the following code:
mydropdown.Items.Clear()
The end result is that it comes...
|
by: Karyn Williams |
last post by:
I am new to Pyton. I am trying to modify and understand a script someone
else wrote. I am trying to make sense of the following code snippet. I know
line 7 would be best coded with regex. I first...
|
by: james.kirin40 |
last post by:
Hi everyone,
I am using Python's re module to extract some data from html. The
following code never returns, and I was wondering if someone can
explain to me why. Is this a problem with my...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |