Anonymous user
Boston Python Workshop 6/Friday/Tutorial: Difference between revisions
Boston Python Workshop 6/Friday/Tutorial (view source)
Revision as of 14:04, 31 March 2012
, 12 years ago→End of Part 2
imported>Jesstess |
imported>Adamf |
||
(11 intermediate revisions by one other user not shown) | |||
Line 210:
===String Concatenation===
You can smoosh strings together (called "concatenation") using the '+' sign:
<pre>
Line 288 ⟶ 290:
print len("")
fish = "humuhumunukunukuapuaʻa"
length = str(len(fish))
print fish + " is a Hawaiian fish whose name is " +
</pre>
Line 361 ⟶ 364:
3.
<pre>
print 2.0 * 123 + str(2.0) * 123
</pre>
Line 399 ⟶ 401:
<ol>
<li>Download the file http://mit.edu/jesstess/www/BostonPythonWorkshop6/nobel.py by right-clicking on it and saying to save it as a ".py" file to your Desktop. The ".py" extension hints that this is a Python script.</li>
<li>Open a command prompt, and use the navigation commands (<code>dir</code> and <code>cd</code> on Windows, <code>ls</code>, <code>pwd</code>, and <code>cd</code> on OS X and Linux) to navigate to your home directory. See [[Boston Python Workshop 6/Friday#Goal_.234:_practice_navigating_the_computer_from_a_command_prompt|navigating from a command prompt]] for a refresher on those commands.</li>
<li>Once you are in your home directory, execute the contents of <code>nobel.py</code> by typing
Line 457 ⟶ 458:
</pre>
Use <code>==</code> to test for equality. Recall that <code>=</code> is used for <i>assignment</i>
This is an important idea and can be a source of bugs until you get used to it: <b>= is assignment, == is comparison</b>.
Line 635 ⟶ 636:
If color had been "purple", that code wouldn't have printed anything.
<b>Remember
==Writing Functions==
Line 742 ⟶ 743:
Functions don't have to return anything, if you don't want them to. They usually return something because we usually want to be able to assign variables to their output.
==End of Part 2==
Line 760 ⟶ 751:
Take a break, stretch, meet some neighbors, and ask the staff if you have any questions about this material.
|