¡@

Home 

python Programming Glossary: mutable

Common pitfalls in Python [duplicate]

http://stackoverflow.com/questions/1011431/common-pitfalls-in-python

gotcha&rsquo s and landmines Today I was bitten again by mutable default arguments after many years. I usually don't use mutable.. default arguments after many years. I usually don't use mutable default arguments unless needed but I think with time I forgot.. is changed then the initial value is changed. If you set a mutable object as a default value you'll get the same object shared..

Python hashable dicts

http://stackoverflow.com/questions/1151658/python-hashable-dicts

this use of key value collections is that they should be immutable but I don't intend to expose the interface to allow them to.. expose the interface to allow them to be changed so either mutable or immutable collections are fine The problem is that python.. to allow them to be changed so either mutable or immutable collections are fine The problem is that python dicts cannot..

Python list doesn't reflect variable change

http://stackoverflow.com/questions/12080552/python-list-doesnt-reflect-variable-change

lists and dicts and that's what makes something in python mutable . Strings on the other hand are not mutable. Once you define.. in python mutable . Strings on the other hand are not mutable. Once you define a string like dead or alive it's one balloon...

When is “i += x” different from “i = i + x” in Python?

http://stackoverflow.com/questions/15376509/when-is-i-x-different-from-i-i-x-in-python

perspective __iadd__ is supposed to be used for modifying mutable objects in place returning the object which was mutated whereas.. __add__ should return a new instance of something. For immutable objects both methods return a new instance but __iadd__ will.. this case i 1 is exactly the same as i i 1 . But with most mutable objects it's a different story As a concrete example a 1 2 3..

Python list problem

http://stackoverflow.com/questions/1959744/python-list-problem

goes into detail on the issues with list references to mutable objects. Their recommended workaround is a list comprehension..

Unexpected feature in a Python list of lists

http://stackoverflow.com/questions/240178/unexpected-feature-in-a-python-list-of-lists

what's going on and how to get around it python list mutable share improve this question When you write x 3 you get essentially..

What are “named tuples” in Python?

http://stackoverflow.com/questions/2970608/what-are-named-tuples-in-python

instead of named tuples Is there any kind of named list a mutable version of the named tuple python tuples namedtuple share.. struct or other common record types except that they are immutable. They were added in Python 2.6 and Python 3.0 although there.. tuple packing. Furthermore you can also replace ordinary immutable classes that have no functions only fields with them. You can..

What is monkey patch?

http://stackoverflow.com/questions/5626193/what-is-monkey-patch

that returns some fixed data. Because Python classes are mutable and methods are just attributes of the class you can do this..

In Python, why can a function modify some arguments as perceived by the caller, but not others?

http://stackoverflow.com/questions/575196/in-python-why-can-a-function-modify-some-arguments-as-perceived-by-the-caller

you pass via names in a caller scope . Objects can be mutable like lists or immutable like integers strings in Python . Mutable.. in a caller scope . Objects can be mutable like lists or immutable like integers strings in Python . Mutable object you can change...

What's the difference between list and tuples in Python?

http://stackoverflow.com/questions/626759/whats-the-difference-between-list-and-tuples-in-python

share improve this question Apart from tuples being immutable there is also a semantic distinction that should guide their.. locations from the list so it makes sense that lists are mutable. On the other hand it probably doesn't make sense to change.. Python documentation also mentions this Tuples are immutable and usually contain an heterogeneous sequence ... . In a statically..

Creating a singleton in python

http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python

is a singleton where all of the reachable objects are immutable. If all objects are immutable than Singleton has no global state.. the reachable objects are immutable. If all objects are immutable than Singleton has no global state as everything is constant... But it is so easy to turn this kind of singleton into mutable one it is very slippery slope. Therefore I am against these..

local var referenced before assignment

http://stackoverflow.com/questions/8934772/local-var-referenced-before-assignment

can change the value of a nonlocal variable is if it is mutable. The simplest way to do this is to wrap your value in a list..

Python: How do I pass a variable by reference?

http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference

but the reference is passed by value some data types are mutable but others aren't So If you pass a mutable object into a method.. data types are mutable but others aren't So If you pass a mutable object into a method the method gets a reference to that same.. will still point at the original object. If you pass an immutable object to a method you still can't rebind the outer reference..