Anonymous user
Boston Python Workshop 3/Data types: Difference between revisions
→Strings
imported>Jesstess |
imported>Jesstess |
||
Line 47:
>>> "Hello"
'Hello'
</pre>
====String concatenation====
<pre>
>>> "Hello" + "World"
HelloWorld
>>> "Hello" + "World" + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> "Hello" + "World" + str(1)
'HelloWorld1'
</pre>
====Printing strings====
<pre>
HelloWorld
>>> print "Hello", "World"
Hello World
Hello World 1
</pre>
Line 57 ⟶ 81:
was US $1.4 million.
</pre>
====Types====
<pre>
Line 62 ⟶ 88:
<type 'str'>
</pre>
▲<b>Printing strings with '+'</b>: print "Hello" + "World"<br />
▲<b>Printing strings with ','</b>: print "Hello", "World", 1<br />
==Booleans==
|