Boston Python workshop 2/Friday tutorial: Difference between revisions

no edit summary
imported>Jesstess
(Created page with 'Type each of the following expressions at the Python prompt (no copying and pasting! You'll learn the concepts better if you type them out yourself). After you type an expression…')
 
imported>Jesstess
No edit summary
Line 93:
Variables can't have spaces or other special characters, and they need to start with a letter. Here are some valid variable names:
 
<code>magic_number = 1500</code><br />
<code>amountOfFlour = .75</code><br />
<code>divisible_by_6 = 54</code>
 
Line 213:
The output from the previous example is really different and interesting; let's break down exactly what is happening:
 
<code>>>> print "Hello" + 1</code><br />
<code>Traceback (most recent call last):</code><br />
<code> File "<stdin>", line 1, in <module></code><br />
<code>TypeError: cannot concatenate 'str' and 'int' objects</code>
 
Line 254:
<pre>
print "Hello" + str(1)
</orepre>
 
Like the <code>type</code> function from before, the <code>str</code> function takes 1 argument, in the example the integer 1. <code>str</code> takes in input and produces a string version of that input as output.
Anonymous user