-
Notifications
You must be signed in to change notification settings - Fork 14
/
05-Strings.html
92 lines (81 loc) · 78.1 KB
/
05-Strings.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>05-Strings</title>
<script type="text/javascript" src="05-Strings_files/MathJax.js" charset="utf-8"></script>
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,
// where it will be undefined, and should prompt a dialog later.
window.mathjax_url = "mathjax/MathJax.js";
</script>
<link rel="stylesheet" href="05-Strings_files/jquery-wijmo.css" type="text/css">
<link rel="stylesheet" href="05-Strings_files/codemirror.css">
<link rel="stylesheet" href="05-Strings_files/markdown.css">
<link rel="stylesheet" href="05-Strings_files/rst.css">
<link rel="stylesheet" href="05-Strings_files/ipython.css">
<link rel="stylesheet" href="05-Strings_files/default.css">
<link rel="stylesheet" href="05-Strings_files/prettify.css">
<link rel="stylesheet" href="05-Strings_files/boilerplate.css" type="text/css">
<link rel="stylesheet" href="05-Strings_files/layout.css" type="text/css">
<link rel="stylesheet" href="05-Strings_files/base.css" type="text/css">
<link rel="stylesheet" href="05-Strings_files/notebook.css" type="text/css">
<link rel="stylesheet" href="05-Strings_files/renderedhtml.css" type="text/css">
<meta name="read_only" content="False">
<style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-family: serif; font-size: 85%; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuTitle {background-color: #CCCCCC; margin: -5px 0 0 0; text-align: center; font-style: italic; font-size: 80%; color: #444444; padding: 2px 0; overflow: hidden}
.MathJax_MenuArrow {position: absolute; right: .5em; color: #666666}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
</style><style type="text/css">#MathJax_Message {position: fixed; left: 1px; bottom: 2px; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style><style type="text/css">@media print { body { overflow: visible !important; } }.ui-widget-content { border: 0px; }</style><style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-family: serif; font-size: 85%; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuTitle {background-color: #CCCCCC; margin: -5px 0 0 0; text-align: center; font-style: italic; font-size: 80%; color: #444444; padding: 2px 0; overflow: hidden}
.MathJax_MenuArrow {position: absolute; right: .5em; color: #666666}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
</style><style type="text/css">#MathJax_Message {position: fixed; left: 1px; bottom: 2px; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style></head><body style="overflow: auto;"><div tabindex="2" class="cell text_cell border-box-sizing ui-widget-content ui-corner-all"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 1px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h1>String "Interpolation"</h1></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [2]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'My favorite number is %d' % 42</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'My favorite number is %d'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[2]:</div><div class="box_flex1 output_subarea output_text"><pre>'My favorite number is 42'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [3]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'My favorite number is %(num)d' % { 'num': 42 }</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'My favorite number is %(num)d'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> { </span><span class="cm-string">'num'</span><span class="cm-null">: </span><span class="cm-number">42</span><span class="cm-null"> }</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[3]:</div><div class="box_flex1 output_subarea output_text"><pre>'My favorite number is 42'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [4]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'The coordinates are (%d,%d)' % (5,6)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'The coordinates are (%d,%d)'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> (</span><span class="cm-number">5</span><span class="cm-null">,</span><span class="cm-number">6</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[4]:</div><div class="box_flex1 output_subarea output_text"><pre>'The coordinates are (5,6)'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [5]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Hello, %s' % 'World'</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Hello, %s'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-string">'World'</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[5]:</div><div class="box_flex1 output_subarea output_text"><pre>'Hello, World'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [6]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Hello, %s' % 42 # calls str() on arguments</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Hello, %s'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span><span class="cm-null"> </span><span class="cm-comment"># calls str() on arguments</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[6]:</div><div class="box_flex1 output_subarea output_text"><pre>'Hello, 42'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [7]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Hello, %r' % 'World' # calls repr() on arguments</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Hello, %r'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-string">'World'</span><span class="cm-null"> </span><span class="cm-comment"># calls repr() on arguments</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[7]:</div><div class="box_flex1 output_subarea output_text"><pre>"Hello, 'World'"</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [8]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Pi, to 3 decimals, is %.3f' % math.pi</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">import</span><span class="cm-null"> </span><span class="cm-variable">math</span></pre><pre><span class="cm-string">'Pi, to 3 decimals, is %.3f'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-variable">math.pi</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[8]:</div><div class="box_flex1 output_subarea output_text"><pre>'Pi, to 3 decimals, is 3.142'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [15]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Padding with spaces: "%20d"' % 42</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Padding with spaces: "%20d"'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[15]:</div><div class="box_flex1 output_subarea output_text"><pre>'Padding with spaces: " 42"'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [14]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Padding with spaces: "%-20d"' % 42</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Padding with spaces: "%-20d"'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[14]:</div><div class="box_flex1 output_subarea output_text"><pre>'Padding with spaces: "42 "'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [13]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Padding with zeros: "%.20d"' % 42</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Padding with zeros: "%.20d"'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[13]:</div><div class="box_flex1 output_subarea output_text"><pre>'Padding with zeros: "00000000000000000042"'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [16]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Float padding: "%10.4f"' % math.pi</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Float padding: "%10.4f"'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-variable">math.pi</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[16]:</div><div class="box_flex1 output_subarea output_text"><pre>'Float padding: 3.1416'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [18]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'Int padding: "%10.4d"' % 42</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'Int padding: "%10.4d"'</span><span class="cm-null"> </span><span class="cm-operator">%</span><span class="cm-null"> </span><span class="cm-number">42</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[18]:</div><div class="box_flex1 output_subarea output_text"><pre>'Int padding: " 0042"'</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 1px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h2>String methods</h2></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [19]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 135px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>The quick brown</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text</span><span class="cm-null"> = </span><span class="cm-string">'''</span></pre><pre><span class="cm-string">The quick brown</span></pre><pre><span class="cm-string"> fox jumped</span></pre><pre><span class="cm-string">over the</span></pre><pre><span class="cm-string"> lazy </span></pre><pre><span class="cm-string">dog</span></pre><pre><span class="cm-string">'''</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [67]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>words = text.split()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">words</span><span class="cm-null"> = </span><span class="cm-variable">text.split</span><span class="cm-null">()</span></pre><pre><span class="cm-variable">words</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[67]:</div><div class="box_flex1 output_subarea output_text"><pre>['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [68]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>' - '.join(words)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">' - '</span><span class="cm-variable">.join</span><span class="cm-null">(</span><span class="cm-variable">words</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[68]:</div><div class="box_flex1 output_subarea output_text"><pre>'The - quick - brown - fox - jumped - over - the - lazy - dog'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [21]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.splitlines()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.splitlines</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[21]:</div><div class="box_flex1 output_subarea output_text"><pre>['', 'The quick brown', ' fox jumped', 'over the', ' lazy ', 'dog']</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [22]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[22]:</div><div class="box_flex1 output_subarea output_text"><pre>'\nThe quick brown\n fox jumped\nover the\n lazy \ndog\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [23]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.strip()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.strip</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[23]:</div><div class="box_flex1 output_subarea output_text"><pre>'The quick brown\n fox jumped\nover the\n lazy \ndog'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [24]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.lstrip()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.lstrip</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[24]:</div><div class="box_flex1 output_subarea output_text"><pre>'The quick brown\n fox jumped\nover the\n lazy \ndog\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [25]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.rstrip()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.rstrip</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[25]:</div><div class="box_flex1 output_subarea output_text"><pre>'\nThe quick brown\n fox jumped\nover the\n lazy \ndog'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [30]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.title()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.title</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[30]:</div><div class="box_flex1 output_subarea output_text"><pre>'\nThe Quick Brown\n Fox Jumped\nOver The\n Lazy \nDog\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [31]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'55'.isdigit()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'55'</span><span class="cm-variable">.isdigit</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[31]:</div><div class="box_flex1 output_subarea output_text"><pre>True</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [32]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'55a'.isdigit()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'55a'</span><span class="cm-variable">.isdigit</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[32]:</div><div class="box_flex1 output_subarea output_text"><pre>False</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [35]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'55a'.isalnum()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'55a'</span><span class="cm-variable">.isalnum</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[35]:</div><div class="box_flex1 output_subarea output_text"><pre>True</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [36]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'33'.isalpha()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'33'</span><span class="cm-variable">.isalpha</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[36]:</div><div class="box_flex1 output_subarea output_text"><pre>False</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [37]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.startswith('\n')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.startswith</span><span class="cm-null">(</span><span class="cm-string">'\n'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[37]:</div><div class="box_flex1 output_subarea output_text"><pre>True</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [38]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.endswith('\n')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.endswith</span><span class="cm-null">(</span><span class="cm-string">'\n'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[38]:</div><div class="box_flex1 output_subarea output_text"><pre>True</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [39]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.index('fox')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.index</span><span class="cm-null">(</span><span class="cm-string">'fox'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[39]:</div><div class="box_flex1 output_subarea output_text"><pre>18</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [40]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text[18:]</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text</span><span class="cm-null">[</span><span class="cm-number">18</span><span class="cm-null">:]</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[40]:</div><div class="box_flex1 output_subarea output_text"><pre>'fox jumped\nover the\n lazy \ndog\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [42]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.find('gopher')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.find</span><span class="cm-null">(</span><span class="cm-string">'gopher'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[42]:</div><div class="box_flex1 output_subarea output_text"><pre>-1</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [43]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.index('gopher')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.index</span><span class="cm-null">(</span><span class="cm-string">'gopher'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text"><pre><span class="ansired">---------------------------------------------------------------------------</span>
<span class="ansired">ValueError</span> Traceback (most recent call last)
<span class="ansigreen">/vagrant/<ipython-input-43-bbb5e3c56822></span> in <span class="ansicyan"><module></span><span class="ansiblue">()</span>
<span class="ansigreen">----> 1</span><span class="ansired"> </span>text<span class="ansiblue">.</span>index<span class="ansiblue">(</span><span class="ansiblue">'gopher'</span><span class="ansiblue">)</span><span class="ansiblue"></span>
<span class="ansired">ValueError</span>: substring not found
</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [44]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'foo bar baz foo'.find('foo')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'foo bar baz foo'</span><span class="cm-variable">.find</span><span class="cm-null">(</span><span class="cm-string">'foo'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[44]:</div><div class="box_flex1 output_subarea output_text"><pre>0</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [46]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'foo bar baz foo'.find('foo', 1)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'foo bar baz foo'</span><span class="cm-variable">.find</span><span class="cm-null">(</span><span class="cm-string">'foo'</span><span class="cm-null">, </span><span class="cm-number">1</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[46]:</div><div class="box_flex1 output_subarea output_text"><pre>12</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [29]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>print 'Hello'.center(80)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-string">'Hello'</span><span class="cm-variable">.center</span><span class="cm-null">(</span><span class="cm-number">80</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre> Hello </pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [47]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'foo bar baz foo'.rfind('foo')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px; visibility: hidden;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'foo bar baz foo'</span><span class="cm-variable">.rfind</span><span class="cm-null">(</span><span class="cm-string">'foo'</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[47]:</div><div class="box_flex1 output_subarea output_text"><pre>12</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [52]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>'foo, bar, baz, foo'.split(',')</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-string">'foo, bar, baz, foo'</span><span class="cm-variable">.split</span><span class="cm-null">(</span><span class="cm-string">','</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[52]:</div><div class="box_flex1 output_subarea output_text"><pre>['foo', ' bar', ' baz', ' foo']</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [54]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>first, rest = 'foo, bar, baz, foo'.split(',', 1)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">first</span><span class="cm-null">, </span><span class="cm-variable">rest</span><span class="cm-null"> = </span><span class="cm-string">'foo, bar, baz, foo'</span><span class="cm-variable">.split</span><span class="cm-null">(</span><span class="cm-string">','</span><span class="cm-null">, </span><span class="cm-number">1</span><span class="cm-null">)</span></pre><pre><span class="cm-variable">rest</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[54]:</div><div class="box_flex1 output_subarea output_text"><pre>' bar, baz, foo'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [55]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>rest, last = 'foo, bar, baz, foo'.rsplit(',', 1)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">rest</span><span class="cm-null">, </span><span class="cm-variable">last</span><span class="cm-null"> = </span><span class="cm-string">'foo, bar, baz, foo'</span><span class="cm-variable">.rsplit</span><span class="cm-null">(</span><span class="cm-string">','</span><span class="cm-null">, </span><span class="cm-number">1</span><span class="cm-null">)</span></pre><pre><span class="cm-variable">rest</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[55]:</div><div class="box_flex1 output_subarea output_text"><pre>'foo, bar, baz'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [56]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.lower()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.lower</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[56]:</div><div class="box_flex1 output_subarea output_text"><pre>'\nthe quick brown\n fox jumped\nover the\n lazy \ndog\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [57]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.upper()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.upper</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[57]:</div><div class="box_flex1 output_subarea output_text"><pre>'\nTHE QUICK BROWN\n FOX JUMPED\nOVER THE\n LAZY \nDOG\n'</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [60]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>text.title().swapcase()</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">text.title</span><span class="cm-null">()</span><span class="cm-variable">.swapcase</span><span class="cm-null">()</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt output_prompt">Out[60]:</div><div class="box_flex1 output_subarea output_text"><pre>'\ntHE qUICK bROWN\n fOX jUMPED\noVER tHE\n lAZY \ndOG\n'</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 1px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h2>String templates</h2></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [61]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 30px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>import string</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-keyword">import</span><span class="cm-null"> </span><span class="cm-variable">string</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [62]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 170px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>I am intrigued by your ideas and wish to </span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">tmpl</span><span class="cm-null"> = </span><span class="cm-variable">string.Template</span><span class="cm-null">(</span><span class="cm-string">'''</span></pre><pre><span class="cm-string">Dear $to,</span></pre><pre> </pre><pre><span class="cm-string">I am intrigued by your ideas and wish to </span></pre><pre><span class="cm-string">subscribe to your newsletter.</span></pre><pre> </pre><pre><span class="cm-string">Best regards,</span></pre><pre><span class="cm-string">$from</span></pre><pre><span class="cm-string">'''</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: none;" class="output vbox"></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [64]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>dct = {'to': 'Rick', 'from': 'Stuart'}</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">dct</span><span class="cm-null"> = {</span><span class="cm-string">'to'</span><span class="cm-null">: </span><span class="cm-string">'Rick'</span><span class="cm-null">, </span><span class="cm-string">'from'</span><span class="cm-null">: </span><span class="cm-string">'Stuart'</span><span class="cm-null">}</span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">tmpl.substitute</span><span class="cm-null">(</span><span class="cm-variable">dct</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>Dear Rick,
I am intrigued by your ideas and wish to
subscribe to your newsletter.
Best regards,
Stuart</pre></div></div></div></div><div tabindex="2" class="cell border-box-sizing code_cell vbox"><div class="input hbox"><div class="prompt input_prompt">In [66]:</div><div class="input_area box-flex1"><div class="CodeMirror CodeMirror-focused"><div style="overflow: hidden; position: relative; width: 1px; height: 0px; top: 0px; left: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-ipython"><div style="position: relative; height: 47px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre><span>print tmpl.safe_substitute(dct)</span></pre></div><div style="position: relative; top: 0px;"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative;" draggable="true"><pre style="top: 0px; left: 0px;" class="CodeMirror-cursor"> </pre><div style=""><pre><span class="cm-variable">dct</span><span class="cm-null"> = { </span><span class="cm-string">'to'</span><span class="cm-null">: </span><span class="cm-string">'Rick'</span><span class="cm-null"> }</span></pre><pre><span class="cm-keyword">print</span><span class="cm-null"> </span><span class="cm-variable">tmpl.safe_substitute</span><span class="cm-null">(</span><span class="cm-variable">dct</span><span class="cm-null">)</span></pre></div></div></div></div></div></div></div></div></div><div style="display: -moz-box;" class="output vbox"><div class="hbox output_area"><div class="prompt"></div><div class="box_flex1 output_subarea output_text output_stream output_stdout"><pre>Dear Rick,
I am intrigued by your ideas and wish to
subscribe to your newsletter.
Best regards,
$from</pre></div></div></div></div><div tabindex="2" class="cell text_cell border-box-sizing"><div style="display: none;" class="text_cell_input"><div class="CodeMirror"><div style="overflow: hidden; position: relative; width: 1px; height: 0px;"><textarea style="position: absolute; width: 2px;" wrap="off" autocorrect="off" autocapitalize="off"></textarea></div><div class="CodeMirror-scroll cm-s-default"><div style="position: relative; height: 10px;"><div style="position: absolute; height: 0; width: 0; overflow: hidden;"><pre>x</pre></div><div style="position: relative"><div style="display: none;" class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div><div class="CodeMirror-lines"><div style="position: relative" draggable="true"><pre class="CodeMirror-cursor"> </pre><div></div></div></div></div></div></div></div></div><div tabindex="-1" class="text_cell_render rendered_html"><h3>Exercises</h3>
<ul>
<li>Write a function that will read a file and return a list of all
the words in the file.</li>
<li>Enhance this function to return a <code>dict</code> containing each
distinct word as a key and the number of occurrences as the
value.</li>
<li>Write a function that takes a list of strings as a parameter
and prints them, in title case, centered for an 80-column
display.</li>
</ul></div></div><div style="height: 30%;" class="end_space"></div></body></html>