Why a calling function in python contains variable equal to value? -


i have started learn python, , ask considered little magic in language.

i note before learning python worked php , there haven't noticed that.

what's going on - have noticed call constructors or methods in python in form.

object.call(variable1 = value1, variable2 = value2) 

for example, in flask:

app.run(debug=true, threaded=true) 

is reason convention? or there semantical reason outgoing language fundamentals? haven't seen in php in python , because i'm surprised. i'm curious if there magic or it's convention read code easier.

these called keyword arguments, , they're used make call more readable.

they can used pass arguments in different order declared parameters, or skip on default parameters pass arguments others, or because function requires keyword arguments… but readability core reason existence.

consider this:

app.run(true, false) 

do have idea 2 arguments mean? if can guess 2 reasonable arguments threading , debugging flags, how can guess 1 comes first? way can figure out type app is, , check app.run method's docstring or definition.

but here:

app.run(debug=true, threaded=false) 

it's obvious means.


it's worth reading faq what difference between arguments , parameters?, , other tutorial sections near 1 linked above. can read reference on function definitions full details on parameters , calls full details on arguments, , inspect module documentation on kinds of parameters.

this blog post attempts summarize in references don't have read way through whole mess. examples @ end should serve show why mixing arguments , parameters in general, keyword arguments , default parameters, argument unpacking , variable parameters, etc. lead astray.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -