Does Python pass by value, or pass by reference?

Neither.

If you twist around how you interpret the terms, you can call it either. Java calls the same evaluation strategy "pass by value", while Ruby calls it "pass by reference".

9

In database apps, you often want to create tables, views, and indices only if they don't already exist, so they do the setup work the first time, but don't blow away all of your data every subsequent time. So SQL has a special "IF NOT EXISTS" clause you can add to the various CREATE statements.

November 7th, 2013

Sometimes you want to write a round-trippable __repr__ method--that is, you want the string representation to be valid Python code that generates an equivalent object to the one you started with.

First, ask yourself whether you really want this.

Many novices notice that, for many types, repr and eval are perfect opposites, and assume that this is a great way to serialize their data:

def save(path, *things): with open(path, 'w') as f: for thing in things: f.write(repr(thing) + '\n') def load(path): with open(path) as f: return [eval(line) f

1
Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.