Anonymous user
Boston Python Workshop 3/Friday/Tutorial: Difference between revisions
Boston Python Workshop 3/Friday/Tutorial (view source)
Revision as of 13:12, 24 September 2011
, 12 years agoProtected "Boston Python Workshop 3/Friday/Tutorial" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))
imported>Jesstess (→Quotes) |
imported>Jesstess m (Protected "Boston Python Workshop 3/Friday/Tutorial" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 228:
<pre>
name = "Jessica"
print "Hello " + name
</pre>
Line 333:
<code>m a happy camper'</code>
which it doesn't understand --
We can use double quotes to avoid this problem:
Line 693:
A <b>function signature</b> tells you how the function will be called. It starts with the keyword <code>def</code>, which tells Python that you are defining a function. Then comes a space, the name of your function, an open parenthesis, the comma-separated input <b>parameters</b> for your function, a close parenthesis, and a colon. Here's what a function signature looks like for a function that takes no arguments:
<code>def myFunction():</code>▼
▲def myFunction():
Here's what a function signature looks like for a function that takes one argument called <code>string</code>:
<code>def myFunction(string):</code>▼
▲def myFunction(string):
And one for a function that takes two arguments:
<code>def myFunction(myList, myInteger):</code>▼
▲def myFunction(myList, myInteger):
Parameters should have names that usefully describe what they are used for in the function.
Line 786 ⟶ 780:
Learning about functions opens up a whole new way for us to practice, using the programming site [http://codingbat.com codingbat.com]. The big goal of this practice section is to get you thinking about how to solve problems in Python.
Please visit http://codingbat.com/home/jessica.mckellar@gmail.com/Friday to complete the practice problems. You don't have to create a CodingBat account to do the exercises, but if you do create an account it'll keep track of which problems you've completed and other statistics.
==End of Part 2==
|