Difference between revisions of "Boston Python Workshop 3/Friday/Tutorial"

imported>Jesstess
imported>Jesstess
* They do some useful bit of work.
* They let us re-use code without having to type it out each time.
* They take input and possibly produce output (we say they <b>return</b> a value). You can assign a variable to this output.
* You call a function by using its name followed by the input in parenthesis.
 
 
Running this assigns the type of <code>my_var</code> -- a boolean -- to <code>x</code>.
 
We also saw the <code>str</code> function, which returns a string representations of an objects so we can print it. For example:
 
<pre>
age = str(23)
print "I am ", age, "years old."
</pre>
 
 
We can right our own functions to encapsulate bits of useful work so we can reuse them. Here's how you do it:
Anonymous user