Python Programming - Wikimedia Commons

Dec 27, 2015 - To extract the source from the PDF file, you can use the pdfdetach tool including in the poppler suite, or the http://www. ..... 28 Database Programming. 153. 28.1 Generic Database .... Gentoo is an example of a distribution that installs Python by default - the package system. Portage depends on Python.
921KB Sizes 5 Downloads 225 Views
Python Programming

en.wikibooks.org

December 27, 2015

On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. A URI to this license is given in the list of figures on page 187. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 179. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 191, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 187. This PDF was generated by the LATEX typesetting software. The LATEX source code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, you can use the pdfdetach tool including in the poppler suite, or the http://www. pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility. Some PDF viewers may also let you save the attachment to a file. After extracting it from the PDF file you have to rename it to source.7z. To uncompress the resulting archive we recommend the use of http://www.7-zip.org/. The LATEX source itself was generated by a program written by Dirk Hünniger, which is freely available under an open source license from http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf.

Contents 1

Overview

3

2

Getting Python 2.1 Python 2 vs Python 3 . . . . . . . . . . 2.2 Installing Python in Windows . . . . . . 2.3 Installing Python on Mac . . . . . . . . 2.4 Installing Python on Unix environments 2.5 Keeping Up to Date . . . . . . . . . . . 2.6 Notes . . . . . . . . . . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

5 5 5 6 6 8 9

3

Interactive mode

11

4

Creating Python programs 4.1 Hello, World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13 13 16 16

5

Basic syntax

17

6

Data types 6.1 Null object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21 25 25

7

Numbers

27

8

Strings 8.1 String operations 8.2 String constants . 8.3 String methods . 8.4 Exercises . . . . . 8.5 External links . .

9

Lists 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8

. . . . .

. . . . .

Overview . . . . . . . List creation . . . . . List Attributes . . . Combining lists . . . Getting pieces of lists Comparing lists . . . Sorting lists . . . . . Iteration . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

.