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

m
Protected "Boston Python Workshop 3/Friday/Tutorial" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))
imported>Jesstess
imported>Jesstess
m (Protected "Boston Python Workshop 3/Friday/Tutorial" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
 
(9 intermediate revisions by 3 users not shown)
Line 224:
<pre>
"Hello" + "World"
</pre>
"Hello", "World"
 
<pre>
name = "Jessica"
print "Hello " + name
</pre>
 
Line 287 ⟶ 291:
</pre>
 
Python is actually turning the integer 1 into a string before printing, and that's why thethat concatenation works: Python does know how to concatenate two strings.
 
We can convert an integer into a string ourselves, using the <code>str</code> function:
Line 295 ⟶ 299:
</pre>
 
Like the <code>type</code> function from before, the <code>str</code> function takes 1 argument. In the above example it took the integer 1. <code>str</code> takes in a Python object as input and produces a string version of that input as output.
 
===String length===
Line 325 ⟶ 329:
</pre>
 
This gives us another <b>traceback</b>, for a new kind of error, a <code>SyntaxError</code>. When Python looks at that expression, it sees the string 'I' and then
 
<code>m a happy camper'</code>
Line 689 ⟶ 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>
<pre>
def myFunction():
</pre>
 
Here's what a function signature looks like for a function that takes one argument called <code>string</code>:
 
<code>def myFunction(string):</code>
<pre>
def myFunction(string):
</pre>
 
And one for a function that takes two arguments:
 
<code>def myFunction(myList, myInteger):</code>
<pre>
def myFunction(myList, myInteger):
</pre>
 
Parameters should have names that usefully describe what they are used for in the function.
Line 782 ⟶ 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.
[codingbat questions TBD]
 
==End of Part 2==
Anonymous user