-
Notifications
You must be signed in to change notification settings - Fork 16
/
PQR2.7.html
7514 lines (7350 loc) · 359 KB
/
PQR2.7.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
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
<!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>
<title>Python 2.7 Quick Reference</title>
<meta http-equiv="Content-Type" content="text/html;charset= iso-8859-1" />
<meta name="description" content="Python 2.7 language Quick Reference, freely available in HTML (several styles) and PDF versions." />
<meta name="keywords" content="Python, language, langage, 2.7, quick, quickref, fast, reference, guide, Richard, Gruet" />
<link href="css/modern.css" rel="stylesheet" type="text/css" title="Modern" media="all" />
<link href="css/modernbw.css" rel="alternate stylesheet" type="text/css" title="Modern Black & White" media="all" />
<link href="css/modern-colored.css" rel="stylesheet" type="text/css" title="Modern Colored" media="all" />
<link href="css/classic.css" rel="alternate stylesheet" type="text/css" title="Classic" media="all" />
<link href="css/highcontrast.css" rel="alternate stylesheet" type="text/css" title="High contrast" media="all" />
<link href="css/printing.css" rel="alternate stylesheet" type="text/css" title="Printing" media="all" />
<script type="text/javascript" src="css/styleswitcher.js"></script>
</head>
<body>
<a id="top" name="top"></a>
<div class="invisible"> Does the web look weird? Ugly? Perhaps that's because your browser
does not support the CSS standard. I recommend you consider updating it. Without CSS, this
and other pages are visible, but nothing like they were meant to be. A very good free browser with
support for all standards is <a target="_top" href="http://www.mozilla.org/products/firefox/">Firefox</a>.
For information about standards and why they are important, please visit the
<a target="_top" href="http://www.webstandards.org/act/campaign/buc/">browser upgrade campaign</a>. </div>
<table class="main" summary="Layout" border="0" cellpadding="0">
<tbody>
<tr>
<td colspan="20" class="logo" height="59">
<h1> Python 2.7 Quick Reference </h1>
</td>
</tr>
<tr>
<td class="content">
<p><span class="noprint"> Style chooser:
<a href="#" onclick="setActiveStyleSheet('Modern'); return false;" title="Modern style (default)">Modern</a>,
<a href="#" onclick="setActiveStyleSheet('Modern Black & White'); return false;" title="Modern B&W style, good for printing">Modern B&W</a>,
<a href="#" onclick="setActiveStyleSheet('Modern Colored'); return false;" title="Modern variant, slightly Colored">Modern Colored</a>,
<a href="#" onclick="setActiveStyleSheet('Classic'); return false;" title="Classic (original) layout">Classic</a>,
<a href="#" onclick="setActiveStyleSheet('High contrast'); return false;" title="Black & White">High contrast</a>
or <a href="#" onclick="setActiveStyleSheet('Printing'); return false;" title="Optimized for A4 paper">Printing</a>
</span><br />
<span class="noprint" style="font-size:x-small"><span style="color:red">[Hint</span>: Use styles Modern B&W or
Printing to print. If you get problems, try printing the <a href="http://rgruet.free.fr/#QuickRef" title="PDF versions">
PDF versions</a> instead]</span>
</p>
<!-- SUMMARY -->
<h2> <a id="contents" name="contents"></a> Contents </h2>
<ul>
<li> <a href="#Frontstuff">Front matter</a> </li>
<li> <a href="#Invocation"><b>Invocation Options</b></a> </li>
<li> <a href="#Environment"><b>Environment variables</b></a> </li>
<li> <a href="#LexEnt"><b>Lexical entities</b></a> :
<a href="#keywords">keywords</a>,
<a href="#Identifiers">identifiers</a>,
<a href="#Strings">string literals</a>,
<a class="since22" href="#BoolConstants">boolean constants</a>,
<a href="#Numbers">numbers</a>,
<a href="#Sequences">sequences</a>,
<a href="#Dictionaries">dictionaries</a>,
<a href="#Sets">sets</a>,
<a href="#operators">operators</a> </li>
<li> <a href="#BasicTypes"><b>Basic types</b> and their operations:</a>
<a href="#None">None</a>, <a href="#bool">bool</a>,
<a href="#NumericTypes">Numeric types</a>,
<a href="#SequenceTypes">sequence types</a>,
<a href="#list">list</a>,
<a href="#dictionary">dictionary</a>,
<a href="#stringMethods">string</a>,
<a href="#files">file</a>,
<a class="since23" href="#set">set</a>,
<a class="since26" href="#namedtuples">named tuples</a>,
<a href="#dates">date/time</a></li>
<li> <a href="#AdvTypes"><b>Advanced types</b></a> </li>
<li> <a href="#Statements"><b>Statements</b>: </a>
<a href="#assignmentOps">assignment</a>,
<a class="since25" href="#conditionalExpr">conditional expressions</a>,
<a href="#controlFlowSts">control flow</a>,
<a href="#exceptionSts">exceptions</a>,
<a href="#NameSpaceSts">name space</a>,
<a href="#FunctionDef">function def</a>,
<a href="#ClassDef">class def</a></li>
<li> <a class="since22" href="#Iterators">Iterators</a>;
<a class="since22" href="#Generators">Generators</a>;
<a class="since22" href="#Descriptors">Descriptors</a>;
<a class="since24" href="#Decorators">Decorators</a></li>
<li> <a href="#BuiltIn"><b>Built-in Functions</b></a> </li>
<li> <a href="#BuiltInExc"><b>Built-in Exceptions</b></a> </li>
<li> <a href="#SpecialMethods">Standard <b>methods & operators redefinition</b> in user-created Classes</a> </li>
<li> <a href="#typeAttributes">Special <b>informative state attributes</b> for some types</a> </li>
<li> <a href="#ImportantModules">Important <b>modules</b></a> :
<a href="#sysModule">sys</a>,
<a href="#osModule">os</a>,
<a href="#posixModule">posix</a>,
<a href="#posixpathModule">posixpath</a>,
<a href="#shutil">shutil</a>,
<a href="#timeModule">time</a>,
<a href="#stringModule">string</a>,
<a href="#reModule" title="Regular Expressions">re</a>,
<a href="#mathModule">math</a>,
<!-- <a href="#getoptModule">getopt</a> -->
<a href="#compressions">compressions</a>
</li>
<li> <a href="#OtherModules"><b>List of modules</b> in the base distribution</a> </li>
<li> <a href="#Workspace">Workspace exploration and idiom hints</a> </li>
<li> <a href="#Emacs">Python mode for Emacs</a> </li>
</ul>
<!-- FRONT STUFF -->
<h2> <a id="Frontstuff" name="Frontstuff"></a> Front matter </h2>
Version 2.7 (<a href="http://docs.python.org/dev/whatsnew/2.7.html">What's new?</a>)<br />
Check updates at <a target="_top" href="http://rgruet.free.fr/#QuickRef">http://rgruet.free.fr/#QuickRef</a>. <br />
Please <b>report</b> errors, inaccuracies and suggestions to
<a href="javascript:location='mailto:\u0070\u0071\u0072\u0040\u0072\u0067\u0072\u0075\u0065\u0074\u002e\u006e\u0065\u0074';void 0">
Richard Gruet</a> (pqr at rgruet.net).<br />
<br />
<!-- LICENSE CREATIVE COMMONS -->
<a target="_blank" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.0/fr/deed.en_US">
<img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/2.0/fr/88x31.png" />
</a> Creative Commons License.
<p />Last updated on <!-- #BeginDate format:Am1 -->April 16, 2013<!-- #EndDate -->.
<dl>
<dt>Apr 16-May 27, 2013</dt>
<dd>Some corrections, see bottom, by <a href="javascript:location='mailto:\u0073\u006d\u0065\u0040\u0069\u0079\u0073\u0069\u006b\u002e\u0063\u006f\u006d;';void 0">Stefan McKinnon Høj-Edwards</a>.</dd>
<dt>Oct, 2011</dt>
<dd>upgraded by Stefan McKinnon Høj-Edwards for Python 2.7</dd>
<dt>Feb 10, 2009</dt>
<dd>upgraded by Richard Gruet and
<a href="javascript:location='mailto:\u0063\u0075\u0076\u0069\u0070\u0065\u0072\u0040\u0067\u006d\u0061\u0069\u006c\u002e\u0063\u006f\u006d';void 0">Josh Stone</a>
for Python 2.6</dd>
<dt>Dec 14, 2006</dt>
<dd>upgraded by Richard Gruet for Python 2.5</dd>
<dt>Feb 17, 2005,</dt>
<dd>upgraded by Richard Gruet for Python 2.4</dd>
<dt>Oct 3, 2003</dt>
<dd>upgraded by Richard Gruet for Python 2.3</dd>
<dt>May 11, 2003, rev 4</dt>
<dd>upgraded by Richard Gruet for Python 2.2 (restyled by <a
href="javascript:location='mailto:\u0070\u0072\u006f\u006a\u0065\u0063\u0074\u0035\u0040\u006f\u0070\u0065\u0072\u0061\u006d\u0061\u0069\u006c\u002e\u0063\u006f\u006d';void 0">Andrei</a>)</dd>
<dt>Aug 7, 2001</dt>
<dd>upgraded by Simon Brunning for Python 2.1 </dd>
<dt>May 16, 2001</dt>
<dd>upgraded by Richard Gruet and <a href="javascript:location='mailto:\u0073\u0062\u0072\u0075\u006e\u006e\u0069\u006e\u0067\u0040\u0062\u0069\u0067\u0066\u006f\u006f\u0074\u002e\u0063\u006f\u006d';void 0">
Simon Brunning</a> for Python 2.0 </dd>
<dt>Jun 18, 2000</dt>
<dd>upgraded by <a
href="javascript:location='mailto:\u0070\u0071\u0072\u0040\u0072\u0067\u0072\u0075\u0065\u0074\u002e\u006e\u0065\u0074';void 0">
Richard Gruet</a> for Python 1.5.2 </dd>
<dt>Oct 20, 1995</dt>
<dd>created by <a href="mailto:[email protected]">Chris Hoffmann</a> for Python 1.3 </dd>
</dl>
Color coding:
<dl>
<dd> <span class="since27">Features added in 2.7 since 2.6</span><br />
<span class="since26">Features added in 2.6 since 2.5</span><br />
<span class="since25">Features added in 2.5 since 2.4</span><br />
<a href="">A link</a>
</dd>
</dl>
Originally based on:
<ul>
<li> Python Bestiary, author: <a href="mailto:[email protected]" target="_blank">Ken Manheimer</a> </li>
<li> <a target="_blank" href="http://www.python.org/doc/current/">Python manuals</a>,
authors: <a href="mailto:[email protected]">Guido van Rossum</a> and Fred Drake </li>
<li> python-mode.el, author: <a href="mailto:[email protected]">Tim Peters</a> </li>
<li> and the readers of <a href="news://comp.lang.python/">comp.lang.python</a></li>
</ul>
<br />
<!-- LINKS -->
Useful links :
<blockquote>
<ul>
<li> <b>Python's nest</b>: <a target="_blank" href="http://www.python.org/">http://www.python.org</a> </li>
<li> <b>Official documentation</b>: <a target="_blank" href="http://docs.python.org/2.7/">http://docs.python.org/2.7/</a>
<span class="noprint">
[<a href="http://docs.python.org/2.7/lib/modindex.html" target="_blank"><b>Module index</b></a>;
<a href="http://docs.python.org/2.7/ref/ref.html" target="_blank"><b>Language Reference</b></a>]
</span>
<!-- SEARCH BOX -->
<div class="noprint">
<form class="search" action="http://docs.python.org/search.html" method="get" target="_blank">
<input type="text" name="q" size="18" />
<input type="submit" value="Search Doc" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
(use Ctrl-F to search the PQR)
</div></li>
<li> <b>Other doc & free books</b> <!-- Todo: check the existance of these and there relevance -->:
<a href="http://www.python.org/doc/faq/" target="_blank">FAQs</a>,
<a target="_blank" href="http://diveintopython.org/">Dive into Python (from 2004)</a>,
<a target="_blank" href="http://aspn.activestate.com/ASPN/Python/Cookbook/">Python Cookbook - Popular Python recipes</a>,
<a target="_blank" href="http://www.mindview.net/Books/TIPython/">Thinking in Python (from 2001)</a>,
<a target="_blank" href="http://gnosis.cx/TPiP/">Text processing in Python (from 2003)</a> </li>
<li> <b>Getting started</b>: <a target="_blank" href="http://docs.python.org/tutorial/index.html">Python Tutorial</a>,
<a target="_blank" href="http://www.richarddooling.com/index.php/2006/03/14/python-on-xp-7-minutes-to-hello-world/">
7mn to Hello World (windows)</a></li>
<li><b>Topics</b>:
<a target="_blank" href="http://docs.python.org/howto/index.html">HOWTOs</a>,
<a target="_blank" href="http://www.python.org/topics/database/">Databases</a>,
<a target="_blank" href="http://wiki.python.org/moin/WebProgramming">Web programming</a>,
<a target="_blank" href="http://pyxml.sourceforge.net/topics/">XML</a>,
<a target="_blank" href="http://pywebsvcs.sourceforge.net/">Web Services</a>,
<a target="_blank" href="http://wiki.python.org/moin/LanguageParsing">Parsers</a>,
<a target="_blank" href="http://www.scipy.org/">NumPy & SciPy - Numeric & Scientific Computing</a>,
<a href="http://wiki.python.org/moin/GuiProgramming" target="_blank">GUI programming</a>,
<a href="http://docs.python.org/distutils/index.html" target="_blank">Distributing</a>
</li>
<li> <b>Where to find packages</b>:
<a target="_blank" href="http://www.python.org/pypi">Python Package Index (PyPI)</a>,
<a target="_blank" href="http://www.python-eggs.org/">Python Eggs</a>,
<a target="_blank" href="http://sourceforge.net/">SourceForge (search "python")</a>,
<a href="http://peak.telecommunity.com/DevCenter/EasyInstall" target="_blank">Easy Install</a>,
<a target="_blank" href="http://www.onlamp.com/python/">O'Reilly Python DevCenter</a> </li>
<li> <b>Wiki</b>: <a target="_blank" href="http://www.python.org/cgi-bin/moinmoin">moinmoin</a> </li>
<li> <b>Newsgroups</b>:
<a target="_blank" href="news://comp.lang.python/">comp.lang.python</a> and
<a target="_blank" href="news://comp.lang.python.announce/">comp.lang.python.announce</a></li>
<li> <b>Misc pages</b>:
<a target="_blank" href="http://www.pythonware.com/daily/">Daily Python URL</a> </li>
<li> <b>Python Development</b>:
<a target="_blank" href="http://www.python.org/dev/">http://www.python.org/dev/</a></li>
<li> <b>Jython</b> - Java implementation of Python:
<a target="_blank" href="http://www.jython.org/">http://www.jython.org/</a> </li>
<li> <b>IronPython</b> - Python on .Net:
<a target="_blank" href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython">http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython</a></li>
<li> <b>ActivePython</b>:
<a target="_blank" href="http://www.activestate.com/ASPN/Python/">http://www.ActiveState.com/ASPN/Python/</a></li>
<li> <b>Help desk</b>:
<a href="mailto:[email protected]">[email protected]</a></li>
<li> 2 excellent (but somehow outdated) <strong>Python reference books</strong>:
<a target="_blank" href="http://www.amazon.com/exec/obidos/ASIN/0735709017/dostoevskintime/102-9999781-1827259">
Python Essential Reference</a> (Python 2.1) by David Beazley & Guido Van Rossum (Other New Riders) and
<a href="http://www.amazon.com/gp/product/0596001886/qid=1138983550/sr=2-1/ref=pd_bbs_b_2_1/104-9016483-6791167?s=books&v=glance&n=283155"
target="_blank">Python in a nutshell</a> by Alex martelli (O'Reilly).</li>
<li><a target="_blank" href="http://www.limsi.fr/Individu/pointal/python/pqrc/">
<b>Python 2.4 Reference Card (cheatsheet)</b></a> by Laurent Pointal, designed for printing (15 pages).</li>
<li><a target="_blank" href="http://infohost.nmt.edu/tcc/help/pubs/python22/">
Online Python 2.2 Quick Reference</a> by the New Mexico Tech Computer Center. </li>
</ul>
</blockquote>
<blockquote>
<b>Tip</b>: From within the Python interpreter, type <code>help</code>, <code>help(<i>object</i>)</code>
or <code>help("<i>name</i>")</code> to get help.
</blockquote>
<!-- INVOCATION OPTIONS -->
<h2> <a id="Invocation" name="Invocation"></a> Invocation Options </h2>
<blockquote>
<b>python</b>[<b>w</b>]
[-<span class="since26">B</span>dEhi<span class="since24">m</span>OQ<span class="since26">s</span>StuUvVWxX<span class="since26">3</span>]
[-c <i>command</i> | <i>scriptFile</i> | - ] [<i>args</i>]<br />
<font size="-1"> (python<b>w</b> does not open a terminal/console; python does)</font>
</blockquote>
<table>
<caption> Invocation Options </caption>
<thead> <tr><th>Option</th> <th>Effect</th></tr></thead>
<tbody>
<tr class="since26">
<td> -B </td>
<td> Prevents module imports from creating <code>.pyc</code> or <code>.pyo</code> files (see also envt variable
<code>PYTHONDONTWRITEBYTECODE=x</code> and attribute <code>sys.dont_write_bytecode</code>). </td>
</tr>
<tr>
<td> -d </td>
<td> Output parser debugging information (also PYTHONDEBUG=x) </td>
</tr>
<tr>
<td> -E </td>
<td> Ignore environment variables (such as PYTHONPATH) </td>
</tr>
<tr>
<td> -h </td>
<td> Print a help message and exit (formerly -?) </td>
</tr>
<tr>
<td> -i </td>
<td> Inspect interactively after running script (also PYTHONINSPECT=x)
and force prompts, even if stdin appears not to be a terminal. </td>
</tr>
<tr class="since24">
<td> -m <i>module</i></td>
<td> Search for <i>module</i> on <code>sys.path</code> and runs the
module as a script. <span class="since25">(Implementation improved in 2.5: module <code>runpy</code>)</span></td>
</tr>
<tr>
<td> -O </td>
<td> Optimize generated bytecode (also PYTHONOPTIMIZE=x). Asserts are suppressed.</td>
</tr>
<tr>
<td> -OO </td>
<td> Remove doc-strings in addition to the -O optimizations.</td>
</tr>
<tr>
<td> -Q <i>arg</i> </td>
<td> Division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew </td>
</tr>
<tr class="since26">
<td> -s </td>
<td> Disables the user-specific module path (also PYTHONNOUSERSITE=x) </td>
</tr>
<tr>
<td> -S </td>
<td> Don't perform <code>import site</code> on initialization.</td>
</tr>
<tr>
<td> -t </td>
<td> Issue warnings about inconsistent tab usage (-tt: issue errors).</td>
</tr>
<tr>
<td> -u </td>
<td> Unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x). </td>
</tr>
<tr class="since20">
<td> -U </td>
<td> Force Python to interpret all string literals as Unicode literals.</td>
</tr>
<tr>
<td> -v </td>
<td> Verbose (trace import statements) (also PYTHONVERBOSE=x). </td>
</tr>
<tr>
<td> -V </td>
<td> Print the Python version number and exit. </td>
</tr>
<tr>
<td> -W <i>arg</i> </td>
<td> Warning control (arg is action:message:category:module:lineno) </td>
</tr>
<tr>
<td> -x </td>
<td> Skip first line of source, allowing use of non-unix Forms of <code>#!cmd</code> </td>
</tr>
<tr>
<td> <strike class="since21">-X</strike> </td>
<td> <strike class="since21">Disable class based built-in exceptions
(for backward compatibility management of exceptions)</strike></td>
</tr>
<tr class="since26">
<td> -3 </td>
<td> Emit a <code>DeprecationWarning</code> for Python 3.x incompatibilities that <code>2to3</code> cannot trivially fix </td>
</tr>
<tr>
<td> -c <i>command</i> </td>
<td> Specify the command to execute (see next section). This terminates the option
list (following options are passed as arguments to the command). </td>
</tr>
<tr>
<td> <i>scriptFile</i> </td>
<td> The name of a python file (.py) to execute. Read from stdin.<br /></td>
</tr>
<tr>
<td> <i>-</i> </td>
<td> Program read from stdin (default; interactive mode if a tty). </td>
</tr>
<tr>
<td> <i>args</i> </td>
<td> Passed to script or command (in <code>sys.argv[1:]</code>)</td>
</tr>
<tr>
<td> </td>
<td> If no scriptFile or command, Python enters interactive mode. </td>
</tr>
</tbody>
</table>
<ul>
<li>Available <b>IDEs</b> in std distrib: <b>IDLE</b> (tkinter based, portable),
<b>Pythonwin</b> (on Windows). Other free IDEs:
<a href="http://ipython.scipy.org/">IPython</a> (enhanced interactive Python shell - 2011),
<a href="http://eric-ide.python-projects.org/index.html">Eric</a> (2011),
<a href="http://pythonide.stani.be">SPE</a> (2010),
<a href="http://boa-constructor.sourceforge.net/">BOA constructor</a> (GUI Builder - 2011),
<a href="http://pydev.org">PyDev</a> (Eclipse plugin - 2011).
</li>
<li>Typical python <b>module header</b> :
<blockquote><code>
#!/usr/bin/env python<br />
<span class="since23"># -*- coding: latin1 -*-</span></code>
</blockquote>
<span class="since23">Since 2.3 the <i>encoding</i> of a Python source file
must be declared as one of the two first lines (or defaults to <b>7 bits Ascii</b>)
[<a href="http://www.python.org/peps/pep-0263.html">PEP-0263</a>],
with the format:</span><br />
<blockquote><code># -*- coding: <i>encoding</i> -*-</code></blockquote>
<span class="since23">Std <i>encodings</i> are defined <a href="http://www.python.org/doc/2.5/lib/standard-encodings.html">here</a>,
e.g. ISO-8859-1 (aka latin1), iso-8859-15 (latin9), UTF-8... Not all encodings supported,
in particular UTF-16 is not supported.
</span><br />
</li>
<li class="since25">It's now a <b>syntax error</b> if a module contains string literals with 8-bit characters but doesn't
have an encoding declaration (was a warning before).</li>
<li class="since25">Since 2.5, <code>from __future__ import <em>feature</em></code> statements must be declared at <b>beginning</b> of source file.
</li>
<li><b>Site customization</b>: File <code>sitecustomize.py</code> is automatically loaded by Python if it exists
in the Python path (ideally located in <code>${PYTHONHOME}/lib/site-packages/</code>).</li>
<li><b>Tip:</b> when launching a Python script on Windows, <br />
<blockquote>
<code><pythonHome>\python myScript.py args ...</code> can be reduced to :<br />
<code>myScript.py args ...</code> if <pythonHome> is in the PATH envt variable, and further reduced to : <br />
<code>myScript args ...</code> provided that <code>.py;.pyw;.pyc;.pyo</code> is added to the <code>PATHEXT</code> envt variable.
</blockquote>
</li>
</ul>
<!-- ENVIRONMENT VARIABLES -->
<h2> <a id="Environment" name="Environment"></a>Environment variables </h2>
<table>
<caption> Environment variables </caption>
<thead>
<tr>
<th> Variable </th>
<th> Effect </th>
</tr>
</thead>
<tbody>
<tr>
<td> PYTHONHOME </td>
<td> Alternate <i>prefix</i> directory (or <i>prefix</i>:<i>exec_prefix</i>).
The default module search path uses <i>prefix</i>/lib</td>
</tr>
<tr>
<td> <b>PYTHONPATH</b> </td>
<td> Augments the default search path for module files. The format is the same as
the shell's <code>$PATH</code>: one or more directory pathnames separated by ':'
or ';' without spaces around (semi-) colons !<br />
On Windows Python first searches for Registry key
<code>HKEY_LOCAL_MACHINE\Software\Python\PythonCore\<i>x.y</i>\PythonPath</code> (default value).
You can create a key named after your application with a default string value giving the root directory
path of your appl.<br /><br />
Alternatively, you can create a text file with a <code>.pth</code> extension, containing the path(s), one per line,
and put the file somewhere in the Python search path (ideally in the <code>site-packages/</code> directory).
It's better to create a .pth for each application, to make easy to uninstall them.<br />
</td>
</tr>
<tr>
<td> PYTHONSTARTUP </td>
<td> If this is the name of a readable file, the Python commands in that file are executed
before the first prompt is displayed in interactive mode (no default).</td>
</tr>
<tr>
<td> PYTHONDEBUG </td>
<td> If non-empty, same as -d option </td>
</tr>
<tr>
<td> PYTHONINSPECT </td>
<td> If non-empty, same as -i option </td>
</tr>
<tr>
<td> PYTHONOPTIMIZE </td>
<td> If non-empty, same as -O option </td>
</tr>
<tr>
<td> PYTHONUNBUFFERED </td>
<td> If non-empty, same as -u option </td>
</tr>
<tr>
<td> PYTHONVERBOSE </td>
<td> If non-empty, same as -v option </td>
</tr>
<tr>
<td> PYTHONCASEOK </td>
<td> If non-empty, ignore case in file/module names (imports) </td>
</tr>
<tr class="since26">
<td> PYTHONDONTWRITEBYTECODE </td>
<td> If non-empty, same as -B option </td>
</tr>
<tr class="since26">
<td> PYTHONIOENCODING </td>
<td> Alternate <code>encodingname</code> or <code>encodingname:errorhandler</code> for stdin, stdout, and stderr,
with the same choices accepted by <code>str.encode()</code>. </td>
</tr>
<tr class="since26">
<td> PYTHONUSERBASE </td>
<td> Provides a private <code>site-packages</code> directory for <b>user-specific</b> modules.
[<a href="http://www.python.org/peps/pep-0370.html">PEP-0370</a>]<br />
- On Unix and Mac OS X, defaults to <code>~/.local/</code>, and modules are found in a version-specific
subdirectory like <code>lib/python2.6/site-packages</code>.<br />
- On Windows, defaults to <code>%APPDATA%/Python</code> and <code>Python26/site-packages</code>.
</td>
</tr>
<tr class="since26">
<td> PYTHONNOUSERSITE </td>
<td> If non-empty, same as -s option </td>
</tr>
<tr class="since27">
<td> PYTHONWARNINGS </td>
<td> Allows controlling warnings, same as <a href="http://docs.python.org/dev/using/cmdline.html#cmdoption-W">-W</a> option </td>
</tr>
</tbody>
</table>
<!--NOTABLE LEXICAL ENTITIES -->
<h2> <a id="LexEnt" name="LexEnt"></a>Notable lexical entities </h2>
<h3> <a id="keywords" name="keywords"></a>Keywords </h3>
<blockquote>
<pre> and del for is raise<br /> assert elif from lambda return<br /> break else global not try<br /> class except if or while<br /> continue exec import pass <span class="since25">with</span><br /> def finally in print <span class="since22">yield</span></pre>
</blockquote>
<ul>
<li> (List of keywords available in std module: <b>keyword</b>)</li>
<li> Illegitimate Tokens (only valid in strings): <code>$ ?</code> (plus <code>@</code> before 2.4)</li>
<li> A statement must all be on a single line. To break a statement over multiple lines, use "<b>\</b>",
as with the C preprocessor.<br />
<u>Exception</u>: can always break when inside any (), [], or {} pair, or in triple-quoted strings. </li>
<li> More than one statement can appear on a line if they are separated with semicolons ("<b>;</b>"). </li>
<li> Comments start with "<code>#</code>" and continue to end of line. </li>
</ul>
<!-- IDENTIFIERS -->
<h3> <a id="Identifiers" name="Identifiers"></a>Identifiers </h3>
<blockquote> (<i>letter</i> | "_") (<i>letter</i> | <i>digit</i> | "_")* </blockquote>
<ul>
<li> Python identifiers keywords, attributes, etc. are <b>case-sensitive</b>.</li>
<li> Special forms: <b>_</b><i>ident</i> (not imported by 'from module import *');
<b>__</b><i>ident</i><b>__</b> (system defined name); __<i>ident</i> (class-private name mangling). </li>
</ul>
<!-- STRING LITERALS -->
<h3> <a id="Strings" name="Strings"></a> String literals </h3>
Two flavors: <code>str</code> (standard 8 bits locale-dependent strings, like ascii, iso 8859-1, utf-8, ...) and
<code>unicode</code> (16 or 32 bits/char in utf-16 mode or 32 bits/char in utf-32 mode);
one common ancestor <code>basestring</code>.
<br /><br />
<table>
<thead><tr><th>Literal</th></tr></thead>
<tbody>
<tr><td> <b>"</b>a string enclosed by double quotes<b>"</b> </td> </tr>
<tr><td> <b>'</b>another string delimited by single quotes and with a " inside<b>'</b> </td></tr>
<tr><td> <b>'''</b>a string containing embedded newlines and quote (') marks, can be
delimited with triple quotes.<b>'''</b> </td></tr>
<tr><td> <b>"""</b> may also use 3- double quotes as delimiters <b>"""</b> </td></tr>
<tr><td> <span class="since26"><b>b"</b>An 8-bit string<b>"</b> - A <code>bytes</code> instance,
a forward-compatible form for an 8-bit string<b>'</b></span> </td></tr>
<tr><td> <span class="since26"><b>B"</b>Another 8-bit string<b>"</b></span> </td></tr>
<tr><td> <span class="since20"><b>u'</b>a <u>unicode</u> string<b>'</b></span> </td></tr>
<tr><td> <span class="since20"><b>U"</b>Another <u>unicode</u> string<b>"</b></span> </td></tr>
<tr><td> <b>r'</b>a <u>raw</u> string where \ are kept (literalized): handy for regular
expressions and windows paths!<b>'</b> </td></tr>
<tr><td> <b>R"</b>another raw string<b>" --</b> raw strings cannot end with a \ </td></tr>
<tr class="since20"><td> <b>ur'</b>a <u>unicode</u> raw string<b>'</b> </td></tr>
<tr class="since20"><td> <b>UR"</b>another raw <u>unicode</u><b>"</b> </td></tr>
</tbody>
</table>
<ul class="noindent">
<li> Use <b>\</b> at end of line to continue a string on next line. </li>
<li> Adjacent strings are concatened, e.g. <code>'Monty ' 'Python'</code> is
the same as <code>'Monty Python'</code>. </li>
<li> <code>u'hello' + ' world'</code> --> <code>u'hello world'</code> (coerced to unicode)</li>
</ul>
<br />
<table>
<caption> String Literal Escapes </caption>
<thead>
<tr><th>Escape</th> <th>Meaning</th> </tr>
</thead>
<tbody>
<tr>
<td> <b>\<i>newline</i></b> </td>
<td> Ignored (escape newline) </td>
</tr>
<tr>
<td> <b>\\</b> </td>
<td> Backslash (\) </td>
</tr>
<tr>
<td> <b>\e</b> </td>
<td> Escape (ESC) </td>
</tr>
<tr>
<td> <b>\v</b> </td>
<td> Vertical Tab (VT) </td>
</tr>
<tr>
<td> <b>\'</b> </td>
<td> Single quote (') </td>
</tr>
<tr>
<td> <b>\f</b> </td>
<td> Formfeed (FF) </td>
</tr>
<tr>
<td> <b>\</b><i>ooo</i> </td>
<td> char with octal value <i>ooo</i> </td>
</tr>
<tr>
<td> <b>\"</b> </td>
<td> Double quote (") </td>
</tr>
<tr>
<td> <b>\n</b> </td>
<td> Linefeed (LF) </td>
</tr>
<tr>
<td> <b>\a</b> </td>
<td> Bell (BEL) </td>
</tr>
<tr>
<td> <b>\r</b> </td>
<td> Carriage Return (CR) </td>
</tr>
<tr>
<td> <b>\x</b><i>hh</i> </td>
<td> char with hex value <i>hh</i> </td>
</tr>
<tr>
<td> <b>\b</b> </td>
<td> Backspace (BS) </td>
</tr>
<tr>
<td> <b>\t</b> </td>
<td> Horizontal Tab (TAB) </td>
</tr>
<tr class="since20">
<td> <b>\u</b><i>xxxx</i> </td>
<td> Character with 16-bit hex value <i>xxxx</i> (unicode only) </td>
</tr>
<tr class="since20">
<td> <b>\U</b><i>xxxxxxxx</i> </td>
<td> Character with 32-bit hex value <i>xxxxxxxx</i> (unicode only) </td>
</tr>
<tr class="since21">
<td> <b>\N{</b><i>name</i><b>}</b> </td>
<td> Character named in the Unicode database (unicode only), e.g.
<code>u'\N{Greek Small Letter Pi}'</code> <=> <code>u'\u03c0'.</code><br />
(Conversely, in module unicodedata, <code>unicodedata.name(u'\u03c0') == 'GREEK SMALL LETTER PI'</code>) </td>
</tr>
<tr>
<td> <b>\<i>AnyOtherChar</i></b> </td>
<td> left as-is, including the backslash, e.g. <code>str('\z') == '\\z'</code></td>
</tr>
</tbody>
</table>
<ul>
<li> NUL byte (<code>\000</code>) is <b>not</b> an end-of-string marker; NULs may be embedded in strings. </li>
<li> Strings (and tuples) are <u>immutable</u>: they cannot be modified. </li>
</ul>
<!-- BOOLEAN CONSTANTS -->
<h3 class="since22"> <a id="BoolConstants" name="BoolConstants"></a>Boolean constants</h3>
<blockquote class="since22">
<ul class="noindent">
<li> <b>True</b> </li>
<li> <b>False</b> </li>
</ul>
<br />
<span class="since23">Since 2.3, they are of new type <code>bool</code>.</span>
</blockquote>
<!-- NUMBERS -->
<h3> <a id="Numbers" name="Numbers"></a>Numbers </h3>
<blockquote>
<ul class="noindent">
<li> <b>Decimal integer</b>: <code>1234, 1234567890546378940<b>L</b></code> (or <code><b>l</b></code>) </li>
<li class="since26"> <b>Binary</b> integer: <code><b>0b</b>10, <b>0B</b>10, <b>0b</b>10101010101010101010101010101010L</code>
(begins with a <code><b>0b</b></code> or <code><b>0B</b></code>) </li>
<li> <b>Octal</b> integer: <code><b>0</b>177, <span class="since26"><b>0o</b>177, <b>0O</b>177,</span>
<b>0</b>177777777777777777L</code> (begins with a <code><b>0</b></code>
<span class="since26">, <code><b>0o</b></code>, or <code><b>0O</b></code></span>) </li>
<li> <b>Hex</b> integer: <code><b>0x</b>FF, <b>0X</b>FFFFffffFFFFFFFFFFL</code>
(begins with <code><b>0x</b></code> or <code><b>0X</b></code>) </li>
<li> <b>Long</b> integer (unlimited precision): <code>1234567890123456<b>L</b></code>
(ends with <code><b>L</b></code> or <code><b>l</b></code>) or <code><b>long(</b>1234<b>)</b></code> </li>
<li> <b>Float</b> (double precision): <code>3<b>.</b>14<b>e-10</b>, .001, 10., 1E3</code> </li>
<li> <b>Complex</b>: <code>1<b>J</b>, 2<b>+</b>3<b>J</b>, 4<b>+</b>5<b>j</b></code> (ends with
<code><b>J</b></code> or <code><b>j</b></code>, <b>+</b> separates (float) real and imaginary parts) </li>
</ul>
<br />
<span class="since22">Integers and long integers are <b>unified</b> starting from release 2.2
(the <code><b>L</b></code> suffix is no longer required)</span>
</blockquote>
<!-- SEQUENCES -->
<h3> <a id="Sequences" name="Sequences"></a>Sequences </h3>
<blockquote>
Strings and tuples are <u>immutable</u>, lists are <u>mutable</u>.
<ul>
<li> <b>Strings</b> (types <code>str</code> and <code>unicode</code>) of length 0, 1, 2 (see <a href="#Strings">above</a>) <br />
'', '1', "12", 'hello\n' </li>
<li> <b>Tuples</b> (type <code>tuple</code>) of length 0, 1, 2, etc:<br />
<b>()</b> (1<b>,</b>) (1,2) # parentheses are optional if len > 0 </li>
<li> <b>Lists</b> (type <code>list</code>) of length 0, 1, 2, etc: <br /> <b>[]</b> [1] [1,2] </li>
</ul>
</blockquote>
<ul>
<li>Indexing is <b>0</b>-based. Negative indices (usually) mean count backwards from end of sequence. </li>
<li> Sequence <b>slicing [</b><i>starting-at-index</i> <b>:</b>
<i>but-less-than-index</i> <span class="since23"><i>[ : step]</i></span><b>]</b>.
Start defaults to 0, end to len(sequence)<span class="since23">, step to 1</span>.
<pre class="since20"> a = (0,1,2,3,4,5,6,7)<br /> a[3] == 3<br /> a[-1] == 7<br /> a[2:4] == (2, 3)<br /> a[1:] == (1, 2, 3, 4, 5, 6, 7)<br /> a[:3] == (0, 1, 2)<br /> a[:] == (0,1,2,3,4,5,6,7) # makes a <b>copy</b> of the sequence.<br /><span
class="since23"> a[::2] == (0, 2, 4, 6) # Only even numbers. <br /> a[::-1] = (7, 6, 5, 4, 3 , 2, 1, 0) # Reverse order.</span></pre>
</li>
</ul>
<!-- DICTIONARIES -->
<h3> <a id="Dictionaries" name="Dictionaries"></a> Dictionaries (Mappings) </h3>
<blockquote>
<u>Dictionaries</u> (type <code>dict</code>) of length 0, 1, 2, etc: <b>{<i>key</i>: value}</b> {1 : 'first'} {1 : 'first', 'two': 2, <i>key</i>:<i>value</i>}
</blockquote>
Keys must be of a <i>hashable</i> type; Values can be any type.<br />
Dictionaries are <i>unordered</i>, ie. iterating over a dictionary provides key/value pairs in arbitrary order.
<code>OrderedDict</code> in the <a href="http://docs.python.org/2.7/library/collections.html"><code>collections</code></a> module
works as regular dictionaries but iterates over keys and values in a guaranteed order depending on when a key was first inserted.
<!-- SETS -->
<h3> <a id="Sets" name="Sets"></a> Sets </h3>
A set kan either be mutable or immutable.
Curly brackets (<code>{}</code>) are used to surround the contents of the resulting mutable set;
set literals are distinguished from dictionaries by not containing colons and values.
An empty <code>{}</code> continues to represent an empty dictionary; use <code>set()</code> for an empty set.
<!-- OPERATORS -->
<h3> <a id="operators" name="operators"></a> Operators and their evaluation order </h3>
<table>
<caption> Operators and their evaluation order </caption>
<thead>
<tr> <th>Highest</th> <th>Operator</th> <th>Comment</th> </tr>
</thead>
<tbody>
<tr>
<td rowspan="14"> </td>
<td> <b>, [</b>...<b>] {</b>...<b>} `</b>...<b>`</b> </td>
<td> Tuple, list & dict. creation; string conv. </td>
</tr>
<tr>
<td> s<b>[</b>i<b>]</b> s<b>[</b>i<b>:</b>j<b>]</b> s<b>.</b><i>attr</i> f<b>(</b>...<b>)</b> </td>
<td> indexing & slicing; attributes, function calls </td>
</tr>
<tr>
<td> <b>+</b>x, <b>-</b>x, <b>~</b>x </td>
<td> Unary operators </td>
</tr>
<tr>
<td> x<b>**</b>y </td>
<td> Power </td>
</tr>
<tr>
<td> x<b>*</b>y x<b>/</b>y x<b>%</b>y</td>
<td> mult, division, modulo </td>
</tr>
<tr>
<td> x<b>+</b>y x<b>-</b>y </td>
<td> addition, substraction </td>
</tr>
<tr>
<td> x<<y x>>y </td>
<td> Bit shifting </td>
</tr>
<tr>
<td> x<b>&</b>y </td>
<td> Bitwise "and"; also intersection of sets</td>
</tr>
<tr>
<td> x<b>^</b>y </td>
<td> Bitwise exclusive or </td>
</tr>
<tr>
<td> x<b>|</b>y </td>
<td> Bitwise "or"; also union of sets </td>
</tr>
<tr>
<td> x<b><</b>y x<b><=</b>y x<b>></b>y x<b>>=</b>y
x<b>==</b>y x<b>!=</b>y x<b><></b>y<br />
x <b>is</b> y x <b>is not</b> y<br />
x <b>in</b> s x <b>not in</b> s </td>
<td> Comparison, <br />
identity, <br />
membership </td>
</tr>
<tr>
<td> <b>not</b> x </td>
<td> boolean negation </td>
</tr>
<tr>
<td> x <b>and</b> y </td>
<td> boolean and </td>
</tr>
<tr>
<td> x <b>or</b> y </td>
<td> boolean or </td>
</tr>
<tr>
<th> Lowest </th>
<td> <b>lambda</b> <i>args</i>: <i>expr</i> </td>
<td> anonymous function </td>
</tr>
</tbody>
</table>
<ul>
<li> Alternate names are defined in module operator (e.g. <code>__add__</code>
and <code>add</code> for +) </li>
<li> Most operators are <a href="#SpecialMethods">overridable</a></li>
</ul>
<!-- BASIC TYPES AND THEIR OPERATIONS -->
<h2> <a id="BasicTypes" name="BasicTypes"></a> Basic types and their operations </h2>
<!-- COMPARISONS -->
<h3> Comparisons (defined between <i>any</i> types) </h3>
<table>
<caption> Comparisons </caption>
<thead>
<tr> <th>Comparison</th> <th>Meaning</th> <th><div align="center"> Notes </div></th></tr>
</thead>
<tbody>
<tr>
<td> <b><</b> </td>
<td> strictly less than </td>
<td> <div align="center"> (1)<br /></div></td>
</tr>
<tr>
<td> <b><=</b> </td>
<td> less than or equal to </td>
<td> </td>
</tr>
<tr>
<td> <b>></b> </td>
<td> strictly greater than </td>
<td> </td>
</tr>
<tr>
<td> <b>>=</b> </td>
<td> greater than or equal to </td>
<td> </td>
</tr>
<tr>
<td> <b>==</b> </td>
<td> equal to </td>
<td> </td>
</tr>
<tr>
<td> <b>!=</b> or <b><></b> </td>
<td> not equal to </td>
<td> </td>
</tr>
<tr>
<td> <b>is</b> </td>
<td> object identity </td>
<td> <div align="center"> (2)</div></td>
</tr>
<tr>
<td> <b>is not</b> </td>
<td> negated object identity </td>
<td> <div align="center"> (2)</div></td>
</tr>
</tbody>
</table>
<u>Notes</u>:
<ul>
<li> Comparison behavior can be overridden for a given class by defining special
method <a href="#cmpOperator">__cmp__</a>. </li>
<li> (1) X < Y < Z < W has expected meaning, unlike C </li>
<li> (2) Compare object identities (i.e. <b>id</b>(object)), not object values. </li>
</ul>
<!-- NONE -->
<h3> <a id="None" name="None"></a> None </h3>
<blockquote>
<ul>
<li> <code>None</code> is used as default return value on functions.
Built-in single object with type <code>NoneType</code>. Might become a keyword in the future.</li>
<li> Input that evaluates to <code>None</code> does not print when running Python interactively. </li>
<li class="since24">None is now a <b>constant</b>; trying to bind a value to the name "None" is now a syntax error.</li>
</ul>
</blockquote>
<!-- BOOLEAN OPERATORS -->
<h3> <a id="bool" name="bool"></a> Boolean operators </h3>
<table>
<caption> Boolean values and operators </caption>
<thead>
<tr>
<th width="355">Value or Operator</th>
<th width="242"> Evaluates to </th>
<th width="114"> <div align="center"> Notes </div></th>
</tr>
</thead>
<tbody>
<tr class="since22">
<td> built-in <b>bool</b>(<i>expr</i>) </td>
<td> <b>True</b> if <i>expr</i> is true, <b>False</b> otherwise. </td>
<td> <div align="center">see <a href="#BoolConstants">True, False</a> </div></td>
</tr>
<tr>
<td> <b>None</b>, numeric zeros, empty sequences and mappings </td>
<td> considered False </td>
<td> </td>
</tr>
<tr>
<td> all other values </td>
<td> considered True </td>
<td> </td>
</tr>
<tr>
<td> <b>not</b> <i>x</i> </td>
<td> <b>True</b> if <i>x</i> is <b>False</b>, else <b>False</b></td>
<td> </td>
</tr>
<tr>
<td> <i>x</i> <b>or</b> <i>y</i> </td>
<td> if <i>x</i> is <b>False</b> then <i>y</i>, else <i>x</i></td>
<td> <div align="center"> (1)<br /></div> </td>
</tr>
<tr>
<td> <i>x</i> <b>and</b> <i>y</i> </td>
<td> if <i>x</i> is <b>False</b> then <i>x</i>, else <i>y</i> </td>
<td> <div align="center"> (1)<br /> </div></td>
</tr>
</tbody>
</table>
<u>Notes</u>:
<ul>
<li> Truth testing behavior can be overridden for a given class by defining special
method <a href="#nonzeroOperator">__nonzero__</a>. </li>
<li> (1) Evaluate second arg only if necessary to determine outcome. </li>
</ul>
<!-- NUMERIC TYPES -->
<h3> <a id="NumericTypes" name="NumericTypes"></a> Numeric types </h3>
<h4> Floats, integers, long integers<span class="since24">, Decimals</span>. </h4>
<blockquote>
<ul>
<li> Floats (type <code>float</code>) are implemented with C doubles. </li>
<li> Integers (type <code>int</code>) are implemented with C longs (signed 32 bits,
maximum value is <code>sys.maxint</code>) </li>
<li> Long integers (type <code>long</code>) have unlimited size (only limit is system resources). </li>
<li class="since22">Integers and long integers are <b>unified</b> starting from release 2.2 (the <b>L</b>
suffix is no longer required).
<span class="since23"><code>int()</code> returns a <code>long</code> integer instead of raising
<code>OverflowError</code></span>.
<span class="since24">Overflowing operations such as <code>2<<32</code> no longer trigger
<code>FutureWarning</code> and return a long integer.</span></li>
<li>
<div class="since24">Since 2.4, new type <code>Decimal</code> introduced (see module: <a href="#decimal_module">decimal</a>)
to compensate for some limitations of the floating point type, in particular with fractions.
Unlike floats, decimal numbers can be represented exactly; exactness is preserved in calculations;
precision is user settable via the <code>Context</code> type [<a href="http://www.python.org/peps/pep-0327.html">PEP 327</a>].</div>
</li>
</ul>
</blockquote>
<!-- OPERATORS ON ALL NUMERIC TYPES -->
<h4> Operators on all numeric types </h4>
<table>
<caption> Operators on all numeric types </caption>
<thead>
<tr> <th>Operation</th> <th>Result</th> <th>Notes</th> </tr>
</thead>
<tbody>
<tr>
<td> <b>abs</b>(<i>x</i>) </td>
<td> the absolute value of <i>x</i> </td>
<td> </td>
</tr>
<tr>
<td> <b>int</b>(<i>x</i>) </td>
<td> <i>x</i> converted to integer </td>
<td> <div align="center">(2)</div></td>
</tr>
<tr>
<td> <b>long</b>(<i>x</i>) </td>
<td> <i>x</i> converted to long integer </td>
<td> <div align="center">(2)</div></td>
</tr>
<tr>
<td> <b>float</b>(<i>x</i>) </td>
<td> <i>x</i> converted to floating point </td>
<td> </td>
</tr>
<tr>
<td> -<i>x</i> </td>
<td> <i>x</i> negated </td>
<td> </td>
</tr>
<tr>
<td> +<i>x</i> </td>
<td> <i>x</i> unchanged </td>
<td> </td>
</tr>
<tr>
<td> <i>x</i> + <i>y</i> </td>
<td> the sum of <i>x</i> and <i>y</i> </td>
<td> </td>
</tr>
<tr>