Jump to content

Boston Python Workshop 7/Friday/Tutorial: Difference between revisions

imported>Jesstess
imported>Jesstess
Line 660:
<b>Step 1: write a function signature</b>
 
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>parametersarguments</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>
Line 672:
<code>def myFunction(myList, myInteger):</code>
 
ParametersArguments should have names that usefully describe what they are used for in the function.
 
We've used the words <b>parameters</b> and <b>arguments</b> seemingly interchangeably to reference the input to functions. The distinction isn't really important right now, but if you're curious: in function signatures the input is called parameters, and when you are calling the function the input is called arguments.
 
<b>Step 2: do useful work inside the function</b>
Line 680 ⟶ 678:
Underneath the function signature you do your useful work. Everything inside the function is indented, just like with if/else blocks, so Python knows that it is a part of the function.
 
You can use the variables passed into the function as parametersarguments, just like you can use variables once you define them outside of functions.
 
<pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.