3737and additional documentation.
3838
3939The Python interpreter is easily extended with new functions and data
40- types implemented in C or C++ (or other languages callable from C ).
40+ types implemented in \C {} or \Cpp {} (or other languages callable from \C {} ).
4141Python is also suitable as an extension language for customizable
4242applications.
4343
4949For a description of standard objects and modules, see the
5050\emph {Python Library Reference } document. The \emph {Python Reference
5151Manual } gives a more formal definition of the language. To write
52- extensions in C or C++ , read the \emph {Extending and Embedding } and
53- \emph {Python/C API } manuals. There are also several books covering
52+ extensions in \C {} or \Cpp {} , read the \emph {Extending and Embedding } and
53+ \emph {Python/\C {} API } manuals. There are also several books covering
5454Python in depth.
5555
5656This tutorial does not attempt to be comprehensive and cover every
@@ -75,15 +75,15 @@ \section{Introduction}
7575If you ever wrote a large shell script, you probably know this
7676feeling: you'd love to add yet another feature, but it's already so
7777slow, and so big, and so complicated; or the feature involves a system
78- call or other function that is only accessible from C \ldots Usually
78+ call or other function that is only accessible from \C {} \ldots Usually
7979the problem at hand isn't serious enough to warrant rewriting the
80- script in C ; perhaps the problem requires variable-length strings or
80+ script in \C {} ; perhaps the problem requires variable-length strings or
8181other data types (like sorted lists of file names) that are easy in
82- the shell but lots of work to implement in C , or perhaps you're not
83- sufficiently familiar with C .
82+ the shell but lots of work to implement in \C {} , or perhaps you're not
83+ sufficiently familiar with \C {} .
8484
85- Another situation: perhaps you have to work with several C libraries,
86- and the usual C write/compile/test/re-compile cycle is too slow. You
85+ Another situation: perhaps you have to work with several \C {} libraries,
86+ and the usual \C {} write/compile/test/re-compile cycle is too slow. You
8787need to develop software more quickly. Possibly perhaps you've
8888written a program that could use an extension language, and you don't
8989want to design a language, write and debug an interpreter for it, then
@@ -92,10 +92,10 @@ \section{Introduction}
9292In such cases, Python may be just the language for you. Python is
9393simple to use, but it is a real programming language, offering much
9494more structure and support for large programs than the shell has. On
95- the other hand, it also offers much more error checking than C , and,
95+ the other hand, it also offers much more error checking than \C {} , and,
9696being a \emph {very-high-level language }, it has high-level data types
9797built in, such as flexible arrays and dictionaries that would cost you
98- days to implement efficiently in C . Because of its more general data
98+ days to implement efficiently in \C {} . Because of its more general data
9999types Python is applicable to a much larger problem domain than
100100\emph {Awk } or even \emph {Perl }, yet many things are at least as easy
101101in Python as in those languages.
@@ -115,7 +115,7 @@ \section{Introduction}
115115It is also a handy desk calculator.
116116
117117Python allows writing very compact and readable programs. Programs
118- written in Python are typically much shorter than equivalent C
118+ written in Python are typically much shorter than equivalent \C {}
119119programs, for several reasons:
120120\begin {itemize }
121121\item
@@ -128,12 +128,12 @@ \section{Introduction}
128128no variable or argument declarations are necessary.
129129\end {itemize }
130130
131- Python is \emph {extensible }: if you know how to program in C it is easy
131+ Python is \emph {extensible }: if you know how to program in \C {} it is easy
132132to add a new built-in function or module to the interpreter, either to
133133perform critical operations at maximum speed, or to link Python
134134programs to libraries that may only be available in binary form (such
135135as a vendor-specific graphics library). Once you are really hooked,
136- you can link the Python interpreter into an application written in C
136+ you can link the Python interpreter into an application written in \C {}
137137and use it as an extension or command language for that application.
138138
139139By the way, the language is named after the BBC show `` Monty Python's
@@ -182,7 +182,7 @@ \section{Invoking the Interpreter}
182182sys.exit()}.
183183
184184The interpreter's line-editing features usually aren't very
185- sophisticated. On Unix , whoever installed the interpreter may have
185+ sophisticated. On \UNIX {} , whoever installed the interpreter may have
186186enabled support for the GNU readline library, which adds more
187187elaborate interactive editing and history features. Perhaps the
188188quickest check to see whether command line editing is supported is
@@ -343,7 +343,7 @@ \subsection{Numbers}
343343The interpreter acts as a simple calculator: you can type an
344344expression at it and it will write the value. Expression syntax is
345345straightforward: the operators \code {+}, \code {-}, \code {*} and \code {/}
346- work just like in most other languages (e.g., Pascal or C ); parentheses
346+ work just like in most other languages (e.g., Pascal or \C {} ); parentheses
347347can be used for grouping. For example:
348348
349349\bcode \begin {verbatim }
@@ -364,7 +364,7 @@ \subsection{Numbers}
364364>>>
365365\end {verbatim }\ecode
366366%
367- Like in C , the equal sign (\code {=}) is used to assign a value to a
367+ Like in \C {} , the equal sign (\code {=}) is used to assign a value to a
368368variable. The value of an assignment is not written:
369369
370370\bcode \begin {verbatim }
@@ -550,7 +550,7 @@ \subsection{Strings}
550550the first line above could also have been written \code {word = 'Help'
551551'A' }; this only works with two literals, not with arbitrary string expressions.
552552
553- Strings can be subscripted (indexed); like in C , the first character
553+ Strings can be subscripted (indexed); like in \C {} , the first character
554554of a string has subscript (index) 0. There is no separate character
555555type; a character is simply a string of size one. Like in Icon,
556556substrings can be specified with the \emph {slice } notation: two indices
@@ -805,12 +805,12 @@ \section{First Steps Towards Programming}
805805
806806\item
807807The \code {while} loop executes as long as the condition (here: \code {b <
808- 10}) remains true. In Python, like in C , any non-zero integer value is
808+ 10}) remains true. In Python, like in \C {} , any non-zero integer value is
809809true; zero is false. The condition may also be a string or list value,
810810in fact any sequence; anything with a non-zero length is true, empty
811811sequences are false. The test used in the example is a simple
812812comparison. The standard comparison operators are written the same as
813- in C : \code {<}, \code {>}, \code {==}, \code {<=}, \code {>=} and \code {!=}.
813+ in \C {} : \code {<}, \code {>}, \code {==}, \code {<=}, \code {>=} and \code {!=}.
814814
815815\item
816816The \emph {body } of the loop is \emph {indented }: indentation is Python's
@@ -889,9 +889,9 @@ \section{If Statements}
889889\section {For Statements }
890890
891891The \code {for} statement in Python differs a bit from what you may be
892- used to in C or Pascal. Rather than always iterating over an
892+ used to in \C {} or Pascal. Rather than always iterating over an
893893arithmetic progression of numbers (like in Pascal), or leaving the user
894- completely free in the iteration test and step (as C ), Python's
894+ completely free in the iteration test and step (as \C {} ), Python's
895895\code {for} statement iterates over the items of any sequence (e.g., a
896896list or a string), in the order that they appear in the sequence. For
897897example (no pun intended):
@@ -968,10 +968,10 @@ \section{The \sectcode{range()} Function}
968968
969969\section {Break and Continue Statements, and Else Clauses on Loops }
970970
971- The \code {break} statement, like in C , breaks out of the smallest
971+ The \code {break} statement, like in \C {} , breaks out of the smallest
972972enclosing \code {for} or \code {while} loop.
973973
974- The \code {continue} statement, also borrowed from C , continues with the
974+ The \code {continue} statement, also borrowed from \C {} , continues with the
975975next iteration of the loop.
976976
977977Loop statements may have an \code {else} clause; it is executed when the
@@ -1084,7 +1084,7 @@ \section{Defining Functions}
10841084\end {verbatim }\ecode
10851085%
10861086You might object that \code {fib} is not a function but a procedure. In
1087- Python, like in C , procedures are just functions that don't return a
1087+ Python, like in \C {} , procedures are just functions that don't return a
10881088value. In fact, technically speaking, procedures do return a value,
10891089albeit a rather boring one. This value is called \code {None} (it's a
10901090built-in name). Writing the value \code {None} is normally suppressed by
@@ -1624,7 +1624,7 @@ \section{More on Conditions}
16241624>>>
16251625\end {verbatim }\ecode
16261626%
1627- Note that in Python, unlike C , assignment cannot occur inside expressions.
1627+ Note that in Python, unlike \C {} , assignment cannot occur inside expressions.
16281628
16291629\section {Comparing Sequences and Other Types }
16301630
@@ -2075,18 +2075,18 @@ \section{Fancier Output Formatting}
20752075 >>>
20762076\end {verbatim }
20772077
2078- Most formats work exactly as in C and require that you pass the proper
2078+ Most formats work exactly as in \C {} and require that you pass the proper
20792079type; however, if you don't you get an exception, not a core dump.
20802080The \verb \%s \ format is more relaxed: if the corresponding argument is
20812081not a string object, it is converted to string using the \verb \str() \
20822082built-in function. Using \verb \* \ to pass the width or precision in
2083- as a separate (integer) argument is supported. The C formats
2083+ as a separate (integer) argument is supported. The \C {} formats
20842084\verb \%n \ and \verb \%p \ are not supported.
20852085
20862086If you have a really long format string that you don't want to split
20872087up, it would be nice if you could reference the variables to be
20882088formatted by name instead of by position. This can be done by using
2089- an extension of C formats using the form \verb \%(name)format \, e.g.
2089+ an extension of \C {} formats using the form \verb \%(name)format \, e.g.
20902090
20912091\begin {verbatim }
20922092 >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
@@ -2895,9 +2895,9 @@ \section{Random remarks}
28952895usable to implement pure abstract data types. In fact, nothing in
28962896Python makes it possible to enforce data hiding --- it is all based
28972897upon convention. (On the other hand, the Python implementation,
2898- written in C , can completely hide implementation details and control
2898+ written in \C {} , can completely hide implementation details and control
28992899access to an object if necessary; this can be used by extensions to
2900- Python written in C .)
2900+ Python written in \C {} .)
29012901
29022902
29032903Clients should use data attributes with care --- clients may mess up
@@ -3174,7 +3174,7 @@ \section{Private variables through name mangling}
31743174\section {Odds and ends }
31753175
31763176Sometimes it is useful to have a data type similar to the Pascal
3177- `` record'' or C `` struct'' , bundling together a couple of named data
3177+ `` record'' or \C {} `` struct'' , bundling together a couple of named data
31783178items. An empty class definition will do nicely, e.g.:
31793179
31803180\begin {verbatim }
@@ -3274,8 +3274,8 @@ \chapter{What Now?}
32743274which gives complete (though terse) reference material about types,
32753275functions, and modules that can save you a lot of time when writing
32763276Python programs. The standard Python distribution includes a
3277- \emph {lot } of code in both C and Python; there are modules to read
3278- Unix mailboxes, retrieve documents via HTTP, generate random numbers,
3277+ \emph {lot } of code in both \C {} and Python; there are modules to read
3278+ \UNIX {} mailboxes, retrieve documents via HTTP, generate random numbers,
32793279parse command-line options, write CGI programs, compress data, and a
32803280lot more; skimming through the Library Reference will give you an idea
32813281of what's available.
0 commit comments