forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonTutorial.html
More file actions
1420 lines (1328 loc) · 72.4 KB
/
PythonTutorial.html
File metadata and controls
1420 lines (1328 loc) · 72.4 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" />
<title>Python Tutorial for Robot Framework Test Library Developers</title>
<style type="text/css">
/* Robot Framework User Guide Style Sheet
This stylesheet contains styles from restructuredText's default
'html4css1.css' and after that modifications needed for Robot Framework User
Guide. These styles are added into the same file against suggestions at
reST's stylesheet HowTo mentioned below, because we want to be able to
embed all styles into the created HTML file. Everything before 'Robot
Framework User Guide Modifications' text is from 'html4css1.css' without
any changes so that part can still be changed easily.
*/
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 5196 2007-06-03 20:25:28Z wiemann $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left {
clear: left }
img.align-right {
clear: right }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font-family: serif ;
font-size: 100% }
pre.literal-block, pre.doctest-block {
margin-left: 2em ;
margin-right: 2em }
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
/* **************************************** *
* Robot Framework User Guide Modifications *
* **************************************** */
/* Tables
- example, tsv-example: test data examples
- messages: log message examples
- tabular: normal tabular information
*/
table.example, table.tsv-example, table.messages, table.tabular {
border: 1px solid #808080;
border-collapse: collapse;
empty-cell: show;
margin: 0.5em 2em;
}
table.example caption, table.tsv-example caption, table.tabular caption {
text-align: left;
padding-bottom: 0.5em;
font-style: italic;
font-size: 0.9em;
width: 100%;
}
table.example th, table.example td, table.tsv-example td {
border: 1px solid #808080;
font-family: arial,helvetica,sans-serif;
height: 1.2em;
font-size: 0.8em;
}
table.example th {
padding: 0.1em 1em;
background: #E0E0E0;
}
table.example td, table.tsv-example td {
padding: 0.1em 1em 0.1em 0.3em;
}
table.tabular th, table.tabular td {
border: 1px solid black;
padding: 0.1em 0.3em;
height: 1.2em;
font-size: 0.8em;
}
table.messages {
border: 1px solid gray;
font-family: monospace;
margin: 1em 2em;
width: 60%;
}
table.messages td {
vertical-align: top;
padding: 0.1em 0.2em;
}
table.messages td.time {
width: 7em;
letter-spacing: -0.05em;
}
table.messages td.level {
width: 5em;
text-align: center;
}
table.messages td.fail, table.messages td.error {
color: red;
}
table.messages td.pass {
color: #009900;
}
table.messages td.warn {
color: #FFCC00;
}
/* Roles -- these are defined in roles.txt file */
.var {
background: #f4f4f4;
font-size: 0.9em;
}
.opt {
font-style: italic;
}
.prog, .code, .cli {
background: #f4f4f4;
font-family: monospace;
}
.msg {
font-family: monospace;
}
.name {
font-style: italic;
}
.path {
font-style: italic;
}
.misc, .literal {
background: #f4f4f4;
}
/* Overridden and modified styles */
cite {
font-size: 0.95em;
}
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
border: 1px solid gray;
margin: 1em 2em;
padding: 0.7em 1em;
font-size: 0.9em;
}
pre.literal-block, pre.doctest-block {
background: #f4f4f4;
}
li, li p.first {
margin-top: 0.3em;
margin-bottom: 0.3em;
}
div.contents li {
margin-top: 0em;
margin-bottom: 0em;
}
a img {
border: 1px solid blue;
}
/* Pygments
- Styles generated using "HtmlFormatter().get_style_defs('.highlight')"
- Changed only background (f8f8f8 -> f4f4f4) and added margin
- For more details see e.g. http://pygments.org/docs/quickstart/
*/
.highlight { background: #f4f4f4; margin: 1em 2em; }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */
</style>
</head>
<body>
<div class="document" id="python-tutorial-for-robot-framework-test-library-developers">
<h1 class="title">Python Tutorial for Robot Framework Test Library Developers</h1>
<!-- This data file has been placed in the public domain. -->
<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<http://docutils.sourceforge.net>. -->
<!-- Roles to use in text like :rolename:`text`. Styled in userguide.css.
- var variables
- opt settings in setting table (e.g. Force Tags), tc/kw tables
(e.g [Documentation]) and command line options (e.g. - -name)
- prog program names (e.g. rebot, risto.py)
- code programming code
- msg test case status and message, as well as log messages and levels
- name keyword, library, test case, test suite, etc. names
- cli command line examples (note that options alone use opt)
- path file names and paths
- misc everything else (synonym to ``text``) -->
<div class="line-block">
<div class="line">Copyright © Nokia Solutions and Networks 2008-2014</div>
<div class="line">Licensed under the <a class="reference external" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported</a> license</div>
</div>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id8">Introduction</a></li>
<li><a class="reference internal" href="#getting-started" id="id9">Getting started</a><ul>
<li><a class="reference internal" href="#installation" id="id10">Installation</a></li>
<li><a class="reference internal" href="#interactive-interpreter" id="id11">Interactive interpreter</a></li>
<li><a class="reference internal" href="#python-editors" id="id12">Python editors</a></li>
</ul>
</li>
<li><a class="reference internal" href="#variables" id="id13">Variables</a><ul>
<li><a class="reference internal" href="#basic-data-types" id="id14">Basic data types</a></li>
<li><a class="reference internal" href="#declaring-variables" id="id15">Declaring variables</a></li>
</ul>
</li>
<li><a class="reference internal" href="#first-program" id="id16">First program</a></li>
<li><a class="reference internal" href="#functions" id="id17">Functions</a><ul>
<li><a class="reference internal" href="#creating-functions" id="id18">Creating functions</a></li>
<li><a class="reference internal" href="#optional-and-named-arguments" id="id19">Optional and named arguments</a></li>
<li><a class="reference internal" href="#variable-number-of-arguments" id="id20">Variable number of arguments</a></li>
<li><a class="reference internal" href="#returning-values" id="id21">Returning values</a></li>
<li><a class="reference internal" href="#documenting-functions" id="id22">Documenting functions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#container-data-types" id="id23">Container data types</a><ul>
<li><a class="reference internal" href="#lists" id="id24">Lists</a></li>
<li><a class="reference internal" href="#tuples" id="id25">Tuples</a></li>
<li><a class="reference internal" href="#dictionaries" id="id26">Dictionaries</a></li>
</ul>
</li>
<li><a class="reference internal" href="#control-flow" id="id27">Control Flow</a><ul>
<li><a class="reference internal" href="#conditional-execution" id="id28">Conditional execution</a></li>
<li><a class="reference internal" href="#looping" id="id29">Looping</a></li>
<li><a class="reference internal" href="#list-comprehensions" id="id30">List comprehensions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#modules" id="id31">Modules</a><ul>
<li><a class="reference internal" href="#importing-modules" id="id32">Importing modules</a></li>
<li><a class="reference internal" href="#creating-modules" id="id33">Creating modules</a></li>
<li><a class="reference internal" href="#module-search-path-pythonpath" id="id34">Module search path (PYTHONPATH)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#advanced-features" id="id35">Advanced features</a><ul>
<li><a class="reference internal" href="#classes-and-instances" id="id36">Classes and instances</a></li>
<li><a class="reference internal" href="#exceptions" id="id37">Exceptions</a></li>
<li><a class="reference internal" href="#regular-expressions" id="id38">Regular expressions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#unit-testing" id="id39">Unit testing</a></li>
<li><a class="reference internal" href="#writing-test-libraries" id="id40">Writing test libraries</a><ul>
<li><a class="reference internal" href="#library-api-basics" id="id41">Library API basics</a></li>
<li><a class="reference internal" href="#executable-example" id="id42">Executable example</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h1><a class="toc-backref" href="#id8">Introduction</a></h1>
<ul class="simple">
<li>This is self learning material to learn how to program using <a class="reference external" href="http://python.org">Python
language</a>. The target is to learn enough Python to be able to start
creating test libraries for <a class="reference external" href="http://robotframework.org">Robot Framework</a>.</li>
<li>Earlier programming experience is expected but not absolutely
necessary.</li>
<li>The main study material for this training is the excellent <em>Dive Into
Python</em> book which is freely available for on-line reading,
downloading or printing from <a class="reference external" href="http://diveintopython.net">http://diveintopython.net</a>. It is
targeted for people who already know how to program but do not know
Python before.</li>
<li>If you are a novice programmer, it might better to start with <a class="reference external" href="http://www.greenteapress.com/thinkpython/thinkpython.html">Think
Python</a> book. It is also available for free and its target audience
is people without any earlier programming knowledge.</li>
<li><a class="reference external" href="http://docs.python.org/tutorial">Python Tutorial</a>, available at <a class="reference external" href="http://python.org">http://python.org</a> and included in
the standard Python installation at least on Windows, is also very
good. Some of the sections in this training refer to it instead of
or in addition to Dive Into Python.</li>
<li>Python coding style guidelines are specified in <a class="reference external" href="http://www.python.org/dev/peps/pep-0008/">PEP-8</a>. Notice that
the Dive Into Python book uses <span class="code">camelCaseStyle</span> instead of the
recommended <span class="code">underline_style</span>.</li>
<li>Another highly recommended style guide, covering many essential
Python idioms and techniques, is <em>Code Like a Pythonista:
Idiomatic Python</em> available at
<a class="reference external" href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html">http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html</a></li>
<li>The official Python website at <a class="reference external" href="http://python.org">http://python.org</a> is a good place to
find more documentation and Python related information in
general.</li>
<li>If you need information about Jython, the Java implementation of
Python, you can start from <a class="reference external" href="http://jython.org">http://jython.org</a>.</li>
<li><em>The Definitive Guide to Jython</em> covers Jython in detail and is
useful especially if you are interested about Jython-Java
integration. It is freely available at <a class="reference external" href="http://jythonbook.com">http://jythonbook.com</a>.</li>
</ul>
</div>
<div class="section" id="getting-started">
<h1><a class="toc-backref" href="#id9">Getting started</a></h1>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#id10">Installation</a></h2>
<ul class="simple">
<li>Most Linux distributions, OS X, and other UNIX like machines have
Python installed by default, but on Windows you probably need to
install it separately. Installers for different platforms can be
found from <a class="reference external" href="http://python.org">http://python.org</a>.</li>
<li>Robot Framework does not yet support Python 3.x versions and this
tutorial is also based on Python 2.x. Any 2.x version up from 2.3 is
sufficient but the latter versions are recommended.</li>
<li>It is highly recommended that you configure your system so that you
can run Python from command line simply by typing <span class="cli">python</span> and pressing
enter.<ul>
<li>On Windows, and possibly on some other systems, this requires
adding Python installation directory into <span class="var">PATH</span> environment
variable. For example <a class="reference external" href="http://code.google.com/p/robotframework/wiki/UserGuide">Robot Framework User Guide</a> has
instructions on how to do it in its <em>Installation</em> section.</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="interactive-interpreter">
<h2><a class="toc-backref" href="#id11">Interactive interpreter</a></h2>
<ul>
<li><p class="first">Open the command prompt and type <span class="cli">python</span>. On Windows you can
also start the interpreter by selecting <tt class="docutils literal">Start > All Programs >
Python 2.x</tt>.</p>
</li>
<li><p class="first">Statements and expressions can be written in the interpreter.
Pressing enter will interpret the line and possible results are
echoed. Try for example:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span>
<span class="go">3</span>
</pre></div>
</li>
<li><p class="first">Use <span class="cli">Ctrl-D</span> to exit on UNIX like machines and <span class="cli">Ctrl-Z</span>
and enter on Windows.</p>
<ul class="simple">
<li>With Python 2.5 and newer you can exit the interpreter also with
command <span class="code">exit()</span>.</li>
</ul>
</li>
<li><p class="first">Dive Into Python has some more examples:
<a class="reference external" href="http://diveintopython.net/installing_python/shell.html">http://diveintopython.net/installing_python/shell.html</a></p>
</li>
</ul>
</div>
<div class="section" id="python-editors">
<h2><a class="toc-backref" href="#id12">Python editors</a></h2>
<ul class="simple">
<li>Most general purpose text editors (Emacs, VIM, UltraEdit, ...) and
IDEs (Eclipse, Netbeans, ...) can be used to edit Python. There are
also some editors specially for Python.</li>
<li>The most important editor features are source highlighting and
handling indentation. Make sure your editor of choice supports them
either natively or via Python plugin or mode.</li>
<li>If you do not know any editor, you can at least get started with
<a class="reference external" href="http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/">IDLE</a>. It is included in the standard Python installation on
Windows and can be installed also on other systems.</li>
</ul>
</div>
</div>
<div class="section" id="variables">
<h1><a class="toc-backref" href="#id13">Variables</a></h1>
<div class="section" id="basic-data-types">
<h2><a class="toc-backref" href="#id14">Basic data types</a></h2>
<ul>
<li><p class="first">Python has strings, integers, floating point numbers, Boolean values
(<span class="code">True</span> and <span class="code">False</span>) similarly as most other programming
languages.</p>
</li>
<li><p class="first">Strings can be enclosed into double or single quotes. Different
quotest do not have any difference like they do for example in Perl.</p>
</li>
<li><p class="first">Unicode strings have a special syntax like <span class="code">u"Hyv\xE4\xE4
y\xF6\t\xE4!"</span>. Using Unicode with Python is not covered otherwise
in this tutorial.</p>
</li>
<li><p class="first"><span class="code">None</span> is a special value meaning nothing similarly as
<span class="code">null</span> in Java.</p>
</li>
<li><p class="first">Try at least these on the interpreter:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="mi">2</span> <span class="o">*</span> <span class="mf">2.5</span>
<span class="go">5.0</span>
<span class="gp">>>> </span><span class="s">'This is easy'</span>
<span class="go">'This is easy'</span>
<span class="gp">>>> </span><span class="s">"Ain't it"</span>
<span class="go">"Ain't it"</span>
</pre></div>
</li>
</ul>
</div>
<div class="section" id="declaring-variables">
<h2><a class="toc-backref" href="#id15">Declaring variables</a></h2>
<ul>
<li><p class="first">All different values can be assigned to variables. Valid characters
in variable identifiers are letters, underscore, and numbers,
although numbers cannot start the variable name.</p>
</li>
<li><p class="first">A variable needs not to be declared, it starts to exist when a value is
assigned for the first time.</p>
</li>
<li><p class="first">There is no need to specify the variable type either as the type is
got from the assigned variable automatically.</p>
</li>
<li><p class="first">Try it out:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">a</span>
<span class="go">3</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="mi">4</span>
<span class="gp">>>> </span><span class="n">a</span><span class="o">*</span><span class="n">b</span>
<span class="go">12</span>
<span class="gp">>>> </span><span class="n">greeting</span> <span class="o">=</span> <span class="s">'Hello'</span>
<span class="gp">>>> </span><span class="n">greeting</span>
<span class="go">'Hello'</span>
<span class="gp">>>> </span><span class="n">greeting</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="go">'HELLO'</span>
</pre></div>
</li>
<li><p class="first">It is even possible to assign multiple variables at once:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="s">'first'</span><span class="p">,</span> <span class="s">'second'</span>
<span class="gp">>>> </span><span class="n">x</span>
<span class="go">'first'</span>
<span class="gp">>>> </span><span class="n">y</span>
<span class="go">'second'</span>
</pre></div>
</li>
</ul>
</div>
</div>
<div class="section" id="first-program">
<h1><a class="toc-backref" href="#id16">First program</a></h1>
<ul>
<li><p class="first">Create a file <span class="path">hello.py</span> with your editor of choice and write
this content into it:</p>
<div class="highlight"><pre><span class="k">print</span> <span class="s">"Hello, world!"</span>
</pre></div>
</li>
<li><p class="first">Then execute the file on the console like this:</p>
<div class="highlight"><pre><span class="go">python hello.py</span>
</pre></div>
</li>
<li><p class="first">As a result you should get <span class="code">Hello, world!</span> printed into the
screen. With Robot Framework keywords such messages would end up
into the log file.</p>
</li>
<li><p class="first">For more interesting examples see Dive Into Python:
<a class="reference external" href="http://diveintopython.net/getting_to_know_python/index.html">http://diveintopython.net/getting_to_know_python/index.html</a></p>
</li>
</ul>
</div>
<div class="section" id="functions">
<h1><a class="toc-backref" href="#id17">Functions</a></h1>
<div class="section" id="creating-functions">
<h2><a class="toc-backref" href="#id18">Creating functions</a></h2>
<ul>
<li><p class="first">Creating functions in Python is super easy. This example uses the
interpreter, but you can also write the code into the previous
<span class="path">hello.py</span> file and execute it.</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="gp">... </span> <span class="k">print</span> <span class="s">"Hello, world!"</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">hello</span><span class="p">()</span>
<span class="go">Hello, world!</span>
</pre></div>
</li>
<li><p class="first">Note that in Python code blocks must be indented (four spaces is the
norm and highly recommended) and you close the block simply by
returning to the earlier indentation level. Inside a block you must
use the indentation level consistently.</p>
</li>
<li><p class="first">Notice also that this <span class="code">hello</span> function is actually already a
valid keyword for Robot Framework!</p>
</li>
<li><p class="first">A function with arguments is not that more complicated:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">print</span> <span class="s">"Hello, </span><span class="si">%s</span><span class="s">!"</span> <span class="o">%</span> <span class="n">name</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">hello</span><span class="p">(</span><span class="s">"Python"</span><span class="p">)</span>
<span class="go">Hello, Python!</span>
<span class="gp">>>> </span><span class="n">hello</span><span class="p">(</span><span class="s">"Robot Framework"</span><span class="p">)</span>
<span class="go">Hello, Robot Framework!</span>
</pre></div>
</li>
<li><p class="first">The hard part in this example is string formatting (i.e. <span class="code">"Hello,
%s!" % name</span>) which uses similar syntax as for example C language.
More information about it can be found e.g. from Dive Into Python:
<a class="reference external" href="http://diveintopython.net/native_data_types/formatting_strings.html">http://diveintopython.net/native_data_types/formatting_strings.html</a></p>
</li>
</ul>
</div>
<div class="section" id="optional-and-named-arguments">
<h2><a class="toc-backref" href="#id19">Optional and named arguments</a></h2>
<ul>
<li><p class="first">Functions can have default values for some or all of its arguments:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">"World"</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">print</span> <span class="s">"Hello, </span><span class="si">%s</span><span class="s">!"</span> <span class="o">%</span> <span class="n">name</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">hello</span><span class="p">()</span>
<span class="go">Hello, World!</span>
<span class="gp">>>> </span><span class="n">hello</span><span class="p">(</span><span class="s">"Robot"</span><span class="p">)</span>
<span class="go">Hello, Robot!</span>
</pre></div>
</li>
<li><p class="first">If there are several optional arguments, it is also possible to
specify only some of them by giving their name along with the value
as the example below illustrates. Those arguments that do not have
default values cannot be omitted.</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">test</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">3</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">print</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">test</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="go">0 1 2 3</span>
<span class="gp">>>> </span><span class="n">test</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">42</span><span class="p">)</span>
<span class="go">0 42 2 3</span>
<span class="gp">>>> </span><span class="n">test</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="go">1 1 10 3</span>
<span class="gp">>>> </span><span class="n">test</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">200</span><span class="p">)</span>
<span class="go">2 1 100 200</span>
<span class="gp">>>> </span><span class="n">test</span><span class="p">(</span><span class="n">b</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n-Identifier"><module></span>
<span class="nc">TypeError</span>: <span class="n-Identifier">test() takes at least 1 non-keyword argument (0 given)</span>
</pre></div>
</li>
<li><p class="first">Robot Framework keywords can have default values but they are always
used with positional arguments. For example, if the above <span class="code">hello</span>
method was used as a keyword, it could be used with zero or one
argument, and <span class="code">test</span> could be used with one to four arguments.</p>
</li>
<li><p class="first">Dive Into Python explains both optional and named arguments very well:
<a class="reference external" href="http://diveintopython.net/power_of_introspection/optional_arguments.html">http://diveintopython.net/power_of_introspection/optional_arguments.html</a></p>
</li>
</ul>
</div>
<div class="section" id="variable-number-of-arguments">
<h2><a class="toc-backref" href="#id20">Variable number of arguments</a></h2>
<ul class="simple">
<li>Function can also be created so that they take any number of
arguments. This is done by prefixing an argument after required and
optional arguments with an asterisk like <span class="code">*args</span>, and it means that
the specified argument gets all the "extra" arguments as a <a class="reference internal" href="#tuples">tuple</a>.</li>
</ul>
<blockquote>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">example</span><span class="p">(</span><span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="o">*</span><span class="n">rest</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">print</span> <span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="p">,</span> <span class="n">rest</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">example</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">1 2 ()</span>
<span class="gp">>>> </span><span class="n">example</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">1 2 (3,)</span>
<span class="gp">>>> </span><span class="n">example</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">1 2 (3, 4, 5)</span>
</pre></div>
</blockquote>
<ul class="simple">
<li>Using variable number of arguments works also with Robot Framework
keywords.</li>
<li>Python tutorial explains everything in this and the prvious section
in detail:
<a class="reference external" href="http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions">http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions</a></li>
</ul>
</div>
<div class="section" id="returning-values">
<h2><a class="toc-backref" href="#id21">Returning values</a></h2>
<ul>
<li><p class="first">Functions can use <span class="code">return</span> statement to return values that can be
assigned to variables or passed to other functions:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">multiply_by_two</span><span class="p">(</span><span class="n">number</span><span class="p">):</span>
<span class="gp">... </span> <span class="k">return</span> <span class="n">number</span> <span class="o">*</span> <span class="mi">2</span>
<span class="gp">...</span>
<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">multiply_by_two</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">result</span>
<span class="go">20</span>
<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">multiply_by_two</span><span class="p">(</span><span class="n">multiply_by_two</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">result</span>
<span class="go">8</span>
</pre></div>
</li>
<li><p class="first">Robot Framework keywords can also return values that can be assigned
to variables and then used as arguments to other keywords.</p>
</li>
</ul>
</div>
<div class="section" id="documenting-functions">
<h2><a class="toc-backref" href="#id22">Documenting functions</a></h2>
<ul>
<li><p class="first">In Python functions, as well as classes and modules, are documented with
so called doc strings:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">def</span> <span class="nf">hello</span><span class="p">():</span>
<span class="gp">... </span> <span class="sd">"""Prints 'Hello, world!' to the standard output."""</span>
<span class="gp">... </span> <span class="k">print</span> <span class="s">"Hello, world!"</span>
<span class="gp">...</span>
</pre></div>
</li>
<li><p class="first">Interestingly the documentation is available dynamically:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="n">hello</span><span class="o">.</span><span class="n">__doc__</span>
<span class="go">Prints 'Hello, world!' to the standard output.</span>
</pre></div>
</li>
<li><p class="first">Doc strings are covered pretty well in Dive Into Python:
<a class="reference external" href="http://diveintopython.net/getting_to_know_python/documenting_functions.html">http://diveintopython.net/getting_to_know_python/documenting_functions.html</a></p>
</li>
<li><p class="first">Robot Framework has <a class="reference external" href="http://code.google.com/p/robotframework/wiki/LibraryDocumentationTool">libdoc.py</a> tool that can generate test library
documentation based on these doc strings. Documenting functions that
are used as keywords is thus very important.</p>
</li>
</ul>
</div>
</div>
<div class="section" id="container-data-types">
<h1><a class="toc-backref" href="#id23">Container data types</a></h1>
<ul class="simple">
<li>Python has a nice set of container data types built into the
language with a really simple syntax similarly as in Perl and
Ruby. You are going to use them a lot!</li>
<li>See Dive Into Python for more information and examples than shown
below: <a class="reference external" href="http://diveintopython.net/native_data_types">http://diveintopython.net/native_data_types</a></li>
</ul>
<div class="section" id="lists">
<h2><a class="toc-backref" href="#id24">Lists</a></h2>
<ul>
<li><p class="first">A list is an ordered collection of items which you normally access
by index.</p>
</li>
<li><p class="first">They also have handy methods like <span class="code">append</span>, <span class="code">insert</span> and
<span class="code">pop</span> to access or alter the list.</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="s">'Some'</span><span class="p">,</span> <span class="s">'strings'</span><span class="p">,</span> <span class="s">'here'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">'Some'</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">'strings'</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="go">'here'</span>
<span class="gp">>>> </span><span class="n">x</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">x</span>
<span class="go">['Some', 'strings', 'HERE', 42]</span>
</pre></div>
</li>
</ul>
</div>
<div class="section" id="tuples">
<h2><a class="toc-backref" href="#id25">Tuples</a></h2>
<ul>
<li><p class="first">A tuple is a list like structure which you cannot alter after creating it.</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="s">'x'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="go">'x'</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s">'new value'</span>
<span class="gt">Traceback (most recent call last):</span>
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n-Identifier"><module></span>
<span class="nc">TypeError</span>: <span class="n-Identifier">'tuple' object does not support item assignment</span>
</pre></div>
</li>
<li><p class="first">Notice that you must use a trailing comma to create a tuple with one
element:</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">empty</span> <span class="o">=</span> <span class="p">()</span>
<span class="gp">>>> </span><span class="n">one</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,)</span>
<span class="gp">>>> </span><span class="n">two</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
</pre></div>
</li>
</ul>
</div>
<div class="section" id="dictionaries">
<h2><a class="toc-backref" href="#id26">Dictionaries</a></h2>
<ul>
<li><p class="first">A dictionary is an unordered collection of key-value pairs. The same
data structure is often called hashmap.</p>
<div class="highlight"><pre><span class="gp">>>> </span><span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s">'x'</span><span class="p">:</span> <span class="s">'some value'</span><span class="p">,</span> <span class="s">'a'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">'b'</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span>
<span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'a'</span><span class="p">]</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'x'</span><span class="p">]</span>
<span class="go">'some value'</span>
<span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'a'</span><span class="p">]</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s">'b'</span><span class="p">]</span>
<span class="gp">>>> </span><span class="n">d</span><span class="p">[</span><span class="s">'tuple'</span><span class="p">]</span> <span class="o">=</span> <span class="n">t</span>
<span class="gp">>>> </span><span class="n">d</span>
<span class="go">{'a': 2, 'x': 'some value', 'b': 2, 'tuple': (1, 2, 'x')}</span>
<span class="gp">>>> </span><span class="s">'x'</span> <span class="ow">in</span> <span class="n">d</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="s">'z'</span> <span class="ow">in</span> <span class="n">d</span>
<span class="go">False</span>
</pre></div>
</li>
</ul>
</div>
</div>
<div class="section" id="control-flow">
<h1><a class="toc-backref" href="#id27">Control Flow</a></h1>
<div class="section" id="conditional-execution">