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

imported>Jesstess
imported>Jesstess
Line 228:
w = "World"
print h + w
print h, w
</pre>
 
Line 239 ⟶ 238:
 
<pre>
print "Hello", 1
print "Hello" + 1
</pre>
Line 273 ⟶ 271:
 
produces a <code>TypeError</code>. We are telling Python to concatenate a string and an integer, and that's not something Python understands how to do.
 
In the similar expression
 
<pre>
print "Hello", 1
</pre>
 
Python is actually turning the integer 1 into a string before printing, and that's why that 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:
Anonymous user