Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5c87c4

Browse files
committed
- added many links into the library reference
- removed use of the string module - fixed some broken markup
1 parent 626d472 commit f5c87c4

1 file changed

Lines changed: 45 additions & 30 deletions

File tree

Doc/tut/tut.tex

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -657,15 +657,14 @@ \subsection{Strings \label{strings}}
657657
expressions:
658658

659659
\begin{verbatim}
660-
>>> import string
661660
>>> 'str' 'ing' # <- This is ok
662661
'string'
663-
>>> string.strip('str') + 'ing' # <- This is ok
662+
>>> 'str'.strip() + 'ing' # <- This is ok
664663
'string'
665-
>>> string.strip('str') 'ing' # <- This is invalid
664+
>>> 'str'.strip() 'ing' # <- This is invalid
666665
File "<stdin>", line 1, in ?
667-
string.strip('str') 'ing'
668-
^
666+
'str'.strip() 'ing'
667+
^
669668
SyntaxError: invalid syntax
670669
\end{verbatim}
671670

@@ -807,6 +806,21 @@ \subsection{Strings \label{strings}}
807806
\end{verbatim}
808807

809808

809+
\begin{seealso}
810+
\seetitle[../lib/typesseq.html]{Sequence Types}%
811+
{Strings, and the Unicode strings described in the next
812+
section, are examples of \emph{sequence types}, and
813+
support the common operations supported by such types.}
814+
\seetitle[../lib/string-methods.html]{String Methods}%
815+
{Both strings and Unicode strings support a large number of
816+
methods for basic transformations and searching.}
817+
\seetitle[../lib/typesseq-strings.html]{String Formatting Operations}%
818+
{The formatting operations invoked when strings and Unicode
819+
strings are the left operand of the \code{\%} operator are
820+
described in more detail here.}
821+
\end{seealso}
822+
823+
810824
\subsection{Unicode Strings \label{unicodeStrings}}
811825
\sectionauthor{Marc-Andre Lemburg}{[email protected]}
812826

@@ -1516,7 +1530,7 @@ \subsection{Keyword Arguments \label{keywordArgs}}
15161530
\end{verbatim}
15171531

15181532
When a final formal parameter of the form \code{**\var{name}} is
1519-
present, it receives a dictionary containing all keyword arguments
1533+
present, it receives a \ulink{dictionary}{../lib/typesmapping.html} containing all keyword arguments
15201534
whose keyword doesn't correspond to a formal parameter. This may be
15211535
combined with a formal parameter of the form
15221536
\code{*\var{name}} (described in the next subsection) which receives a
@@ -1978,9 +1992,10 @@ \section{Tuples and Sequences \label{tuples}}
19781992

19791993
We saw that lists and strings have many common properties, such as
19801994
indexing and slicing operations. They are two examples of
1981-
\emph{sequence} data types. Since Python is an evolving language,
1982-
other sequence data types may be added. There is also another
1983-
standard sequence data type: the \emph{tuple}.
1995+
\ulink{\emph{sequence} data types}{../lib/typesseq.html}. Since
1996+
Python is an evolving language, other sequence data types may be
1997+
added. There is also another standard sequence data type: the
1998+
\emph{tuple}.
19841999

19852000
A tuple consists of a number of values separated by commas, for
19862001
instance:
@@ -2050,7 +2065,8 @@ \section{Tuples and Sequences \label{tuples}}
20502065

20512066
\section{Dictionaries \label{dictionaries}}
20522067

2053-
Another useful data type built into Python is the \emph{dictionary}.
2068+
Another useful data type built into Python is the
2069+
\ulink{\emph{dictionary}}{../lib/typesmapping.html}.
20542070
Dictionaries are sometimes found in other languages as ``associative
20552071
memories'' or ``associative arrays''. Unlike sequences, which are
20562072
indexed by a range of numbers, dictionaries are indexed by \emph{keys},
@@ -2078,11 +2094,11 @@ \section{Dictionaries \label{dictionaries}}
20782094
associated with that key is forgotten. It is an error to extract a
20792095
value using a non-existent key.
20802096

2081-
The \code{keys()} method of a dictionary object returns a list of all
2097+
The \method{keys()} method of a dictionary object returns a list of all
20822098
the keys used in the dictionary, in random order (if you want it
2083-
sorted, just apply the \code{sort()} method to the list of keys). To
2099+
sorted, just apply the \method{sort()} method to the list of keys). To
20842100
check whether a single key is in the dictionary, use the
2085-
\code{has_key()} method of the dictionary.
2101+
\method{has_key()} method of the dictionary.
20862102

20872103
Here is a small example using a dictionary:
20882104

@@ -2872,11 +2888,10 @@ \section{Fancier Output Formatting \label{formatting}}
28722888
Here are two ways to write a table of squares and cubes:
28732889
28742890
\begin{verbatim}
2875-
>>> import string
28762891
>>> for x in range(1, 11):
2877-
... print string.rjust(repr(x), 2), string.rjust(repr(x*x), 3),
2892+
... print repr(x).rjust(2), repr(x*x).rjust(3),
28782893
... # Note trailing comma on previous line
2879-
... print string.rjust(repr(x*x*x), 4)
2894+
... print repr(x*x*x).rjust(4)
28802895
...
28812896
1 1 1
28822897
2 4 8
@@ -2906,28 +2921,27 @@ \section{Fancier Output Formatting \label{formatting}}
29062921
(Note that one space between each column was added by the way
29072922
\keyword{print} works: it always adds spaces between its arguments.)
29082923
2909-
This example demonstrates the function \function{string.rjust()},
2924+
This example demonstrates the \method{rjust()} method of string objects,
29102925
which right-justifies a string in a field of a given width by padding
2911-
it with spaces on the left. There are similar functions
2912-
\function{string.ljust()} and \function{string.center()}. These
2913-
functions do not write anything, they just return a new string. If
2926+
it with spaces on the left. There are similar methods
2927+
\method{ljust()} and \method{center()}. These
2928+
methods do not write anything, they just return a new string. If
29142929
the input string is too long, they don't truncate it, but return it
29152930
unchanged; this will mess up your column lay-out but that's usually
29162931
better than the alternative, which would be lying about a value. (If
29172932
you really want truncation you can always add a slice operation, as in
2918-
\samp{string.ljust(x,~n)[0:n]}.)
2933+
\samp{x.ljust(~n)[:n]}.)
29192934
2920-
There is another function, \function{string.zfill()}, which pads a
2935+
There is another method, \method{zfill()}, which pads a
29212936
numeric string on the left with zeros. It understands about plus and
29222937
minus signs:
29232938
29242939
\begin{verbatim}
2925-
>>> import string
2926-
>>> string.zfill('12', 5)
2940+
>>> '12'.zfill(5)
29272941
'00012'
2928-
>>> string.zfill('-3.14', 7)
2942+
>>> '-3.14'.zfill(7)
29292943
'-003.14'
2930-
>>> string.zfill('3.14159265359', 5)
2944+
>>> '3.14159265359'.zfill(5)
29312945
'3.14159265359'
29322946
\end{verbatim}
29332947
@@ -3110,7 +3124,7 @@ \subsection{The \module{pickle} Module \label{pickle}}
31103124
Strings can easily be written to and read from a file. Numbers take a
31113125
bit more effort, since the \method{read()} method only returns
31123126
strings, which will have to be passed to a function like
3113-
\function{string.atoi()}, which takes a string like \code{'123'} and
3127+
\function{int()}, which takes a string like \code{'123'} and
31143128
returns its numeric value 123. However, when you want to save more
31153129
complex data types like lists, dictionaries, or class instances,
31163130
things get a lot more complicated.
@@ -3297,12 +3311,12 @@ \section{Handling Exceptions \label{handling}}
32973311
handle the exception as well):
32983312
32993313
\begin{verbatim}
3300-
import string, sys
3314+
import sys
33013315
33023316
try:
33033317
f = open('myfile.txt')
33043318
s = f.readline()
3305-
i = int(string.strip(s))
3319+
i = int(s.strip())
33063320
except IOError, (errno, strerror):
33073321
print "I/O error(%s): %s" % (errno, strerror)
33083322
except ValueError:
@@ -4466,7 +4480,8 @@ \section{Key Bindings \label{keyBindings}}
44664480
\end{verbatim}
44674481
44684482
in your \file{\~{}/.inputrc}. (Of course, this makes it harder to
4469-
type indented continuation lines.)
4483+
type indented continuation lines if you're accustomed to using
4484+
\kbd{Tab} for that purpose.)
44704485
44714486
Automatic completion of variable and module names is optionally
44724487
available. To enable it in the interpreter's interactive mode, add

0 commit comments

Comments
 (0)