Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cd40274f
Commit
cd40274f
authored
Sep 10, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markup nits.
Fixes/index improvements from Michael Ernst <mernst@cs.washington.edu>.
parent
a6f1efd2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
65 deletions
+63
-65
Doc/lib/libstdtypes.tex
Doc/lib/libstdtypes.tex
+63
-65
No files found.
Doc/lib/libstdtypes.tex
View file @
cd40274f
\section
{
Built-in Types
}
\label
{
types
}
\section
{
Built-in Types
\label
{
types
}}
The following sections describe the standard types that are built into
the interpreter. These are the numeric types, sequence types, and
...
...
@@ -15,8 +14,7 @@ implicitly used when an object is written by the \code{print} statement.
\stindex
{
print
}
\subsection
{
Truth Value Testing
}
\label
{
truth
}
\subsection
{
Truth Value Testing
\label
{
truth
}}
Any object can be tested for truth value, for use in an
\code
{
if
}
or
\code
{
while
}
condition or as operand of the Boolean operations below.
...
...
@@ -27,11 +25,10 @@ The following values are considered false:
\indexii
{
Boolean
}{
operations
}
\index
{
false
}
\setindexsubitem
{
(Built-in object)
}
\begin{itemize}
\item
\code
{
None
}
\
ttindex
{
None
}
\
withsubitem
{
(Built-in object)
}{
\ttindex
{
None
}
}
\item
zero of any numeric type, e.g.,
\code
{
0
}
,
\code
{
0L
}
,
\code
{
0.0
}
.
...
...
@@ -40,7 +37,7 @@ The following values are considered false:
\item
any empty mapping, e.g.,
\code
{
\{\}
}
.
\item
instances of user-defined classes, if the class defines a
\
code
{__
nonzero
__
()
}
or
\code
{__
len
__
()
}
method, when that
\
method
{__
nonzero
__
()
}
or
\method
{__
len
__
()
}
method, when that
method returns zero.
\end{itemize}
...
...
@@ -56,8 +53,7 @@ stated. (Important exception: the Boolean operations
their operands.)
\subsection
{
Boolean Operations
}
\label
{
boolean
}
\subsection
{
Boolean Operations
\label
{
boolean
}}
These are the Boolean operations, ordered by ascending priority:
\indexii
{
Boolean
}{
operations
}
...
...
@@ -88,8 +84,7 @@ These only evaluate their second argument if needed for their outcome.
\end{description}
\subsection
{
Comparisons
}
\label
{
comparisons
}
\subsection
{
Comparisons
\label
{
comparisons
}}
Comparison operations are supported by all objects. They all have the
same priority (which is higher than that of the Boolean operations).
...
...
@@ -150,8 +145,7 @@ Two more operations with the same syntactic priority, \samp{in} and
\opindex
{
not in
}
\subsection
{
Numeric Types
}
\label
{
typesnumeric
}
\subsection
{
Numeric Types
\label
{
typesnumeric
}}
There are four numeric types:
\dfn
{
plain integers
}
,
\dfn
{
long integers
}
,
\dfn
{
floating point numbers
}
, and
\dfn
{
complex numbers
}
.
...
...
@@ -302,8 +296,7 @@ division by \code{pow(2, \var{n})} without overflow check.
\end{description}
\subsection
{
Sequence Types
}
\label
{
typesseq
}
\subsection
{
Sequence Types
\label
{
typesseq
}}
There are three sequence types: strings, lists and tuples.
...
...
@@ -481,16 +474,16 @@ The following operations are defined on mutable sequence types (where
\indexii
{
subscript
}{
assignment
}
\indexii
{
slice
}{
assignment
}
\stindex
{
del
}
\
setindexsubitem
{
(list method)
}
\ttindex
{
append
}
\ttindex
{
count
}
\ttindex
{
index
}
\ttindex
{
insert
}
\ttindex
{
pop
}
\ttindex
{
remove
}
\ttindex
{
reverse
}
\ttindex
{
sort
}
\
withsubitem
{
(list method)
}{
%
\ttindex
{
append
}
%
\ttindex
{
count
}
%
\ttindex
{
index
}
%
\ttindex
{
insert
}
%
\ttindex
{
pop
}
%
\ttindex
{
remove
}
%
\ttindex
{
reverse
}
%
\ttindex
{
sort
}
%
}
\noindent
Notes:
\begin{description}
...
...
@@ -519,8 +512,7 @@ by default the last item is removed and returned.
\end{description}
\subsection
{
Mapping Types
}
\label
{
typesmapping
}
\subsection
{
Mapping Types
\label
{
typesmapping
}}
A
\dfn
{
mapping
}
object maps values of one type (the key type) to
arbitrary objects. Mappings are mutable objects. There is currently
...
...
@@ -552,20 +544,26 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
\lineiii
{
\var
{
a
}
.clear()
}{
remove all items from
\code
{
a
}}{}
\lineiii
{
\var
{
a
}
.copy()
}{
a (shallow) copy of
\code
{
a
}}{}
\lineiii
{
\var
{
a
}
.has
_
key(
\var
{
k
}
)
}{
\code
{
1
}
if
\var
{
a
}
has a key
\var
{
k
}
, else
\code
{
0
}}{}
\lineiii
{
\var
{
a
}
.items()
}{
a copy of
\var
{
a
}
's list of (
key, item
) pairs
}{
(2)
}
\lineiii
{
\var
{
a
}
.items()
}{
a copy of
\var
{
a
}
's list of (
\var
{
key
}
,
\var
{
value
}
) pairs
}{
(2)
}
\lineiii
{
\var
{
a
}
.keys()
}{
a copy of
\var
{
a
}
's list of keys
}{
(2)
}
\lineiii
{
\var
{
a
}
.update(
\var
{
b
}
)
}{
\code
{
for k, v in
\var
{
b
}
.items():
\var
{
a
}
[k] = v
}}{
(3)
}
\lineiii
{
\var
{
a
}
.values()
}{
a copy of
\var
{
a
}
's list of values
}{
(2)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
\optional
{
,
\var
{
f
}}
)
}{
the
item
of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
\optional
{
,
\var
{
f
}}
)
}{
the
value
of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\end{tableiii}
\indexiii
{
operations on
}{
mapping
}{
types
}
\indexiii
{
operations on
}{
dictionary
}{
type
}
\stindex
{
del
}
\bifuncindex
{
len
}
\setindexsubitem
{
(dictionary method)
}
\ttindex
{
keys
}
\ttindex
{
has
_
key
}
\withsubitem
{
(dictionary method)
}{
%
\ttindex
{
clear
}
%
\ttindex
{
copy
}
%
\ttindex
{
has
_
key
}
%
\ttindex
{
items
}
%
\ttindex
{
keys
}
%
\ttindex
{
update
}
%
\ttindex
{
values
}
%
\ttindex
{
get
}
%
}
\noindent
Notes:
\begin{description}
...
...
@@ -581,8 +579,7 @@ and \var{k} is not in the map, \code{None} is returned.
\end{description}
\subsection
{
Other Built-in Types
}
\label
{
typesother
}
\subsection
{
Other Built-in Types
\label
{
typesother
}}
The interpreter supports several other kinds of objects.
Most of these support only one or two operations.
...
...
@@ -650,7 +647,8 @@ calling \code{\var{m}.im_func(\var{m}.im_self, \var{arg-1},
See the
\emph
{
Python Reference Manual
}
for more information.
\subsubsection
{
Code Objects
}
\subsubsection
{
Code Objects
\label
{
bltin-code-objects
}}
\obindex
{
code
}
Code objects are used by the implementation to represent
...
...
@@ -661,7 +659,7 @@ returned by the built-in \code{compile()} function and can be
extracted from function objects through their
\code
{
func
_
code
}
attribute.
\bifuncindex
{
compile
}
\
ttindex
{
func
_
code
}
\
withsubitem
{
(code object attribute)
}{
\ttindex
{
func
_
code
}
}
A code object can be executed or evaluated by passing it (instead of a
source string) to the
\code
{
exec
}
statement or the built-in
...
...
@@ -671,8 +669,8 @@ source string) to the \code{exec} statement or the built-in
See the
\emph
{
Python Reference Manual
}
for more information.
\subsubsection
{
Type Objects
}
\
label
{
bltin-type-objects
}
\
subsubsection
{
Type Objects
\label
{
bltin-type-objects
}
}
Type objects represent the various object types. An object's type is
accessed by the built-in function
\code
{
type()
}
. There are no special
...
...
@@ -683,8 +681,8 @@ for all standard built-in types.
Types are written like this:
\code
{
<type 'int'>
}
.
\subsubsection
{
The Null Object
}
\
label
{
bltin-null-object
}
\
subsubsection
{
The Null Object
\label
{
bltin-null-object
}
}
This object is returned by functions that don't explicitly return a
value. It supports no special operations. There is exactly one null
...
...
@@ -692,8 +690,8 @@ object, named \code{None} (a built-in name).
It is written as
\code
{
None
}
.
\subsubsection
{
The Ellipsis Object
}
\
label
{
bltin-ellipsis-object
}
\
subsubsection
{
The Ellipsis Object
\label
{
bltin-ellipsis-object
}
}
This object is used by extended slice notation (see the
\emph
{
Python
Reference Manual
}
). It supports no special operations. There is
...
...
@@ -701,14 +699,13 @@ exactly one ellipsis object, named \code{Ellipsis} (a built-in name).
It is written as
\code
{
Ellipsis
}
.
\subsubsection
{
File Objects
}
\label
{
bltin-file-objects
}
\subsubsection
{
File Objects
\label
{
bltin-file-objects
}}
File objects are implemented using
\C
{}
's
\code
{
stdio
}
package and can be
created with the built-in function
\code
{
open()
}
described under
Built-in Functions below. They are also returned by some other
built-in functions and methods, e.g.
\ \
code
{
posix.popen()
}
and
\
code
{
posix.fdopen()
}
and the
\code
{
makefile()
}
method of socket
built-in functions and methods, e.g.
\ \
function
{
posix.popen()
}
and
\
function
{
posix.fdopen()
}
and the
\method
{
makefile()
}
method of socket
objects.
\bifuncindex
{
open
}
\refbimodindex
{
posix
}
...
...
@@ -851,30 +848,31 @@ describes code objects, stack frame objects, traceback objects, and
slice objects.
\subsection
{
Special Attributes
}
\label
{
specialattrs
}
\subsection
{
Special Attributes
\label
{
specialattrs
}}
The implementation adds a few special read-only attributes to several
object types, where they are relevant:
\begin{itemize}
\item
\code
{
\var
{
x
}
.
__
dict
__}
is a dictionary of some sort used to store an
object's (writable) attributes;
\begin{memberdescni}
{__
dict
__}
A dictionary of some sort used to store an
object's (writable) attributes.
\end{memberdescni}
\
item
\code
{
\var
{
x
}
.
__
methods
__}
lists
the methods of many built-in object types,
\
begin{memberdescni}
{__
methods
__}
List of
the methods of many built-in object types,
e.g.,
\code
{
[].
__
methods
__}
yields
\code
{
['append', 'count', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
}
;
\code
{
['append', 'count', 'index', 'insert', 'pop', 'remove',
'reverse', 'sort']
}
.
\end{memberdescni}
\item
\code
{
\var
{
x
}
.
__
members
__}
lists data attributes;
\begin{memberdescni}
{__
members
__}
Similar to
\member
{__
methods
__}
, but lists data attributes.
\end{memberdescni}
\item
\code
{
\var
{
x
}
.
__
class
__}
is the class to which a class instance belongs;
\begin{memberdescni}
{__
class
__}
The class to which a class instance belongs.
\end{memberdescni}
\item
\code
{
\var
{
x
}
.
__
bases
__}
is the tuple of base classes of a class object.
\end{itemize}
\begin{memberdescni}
{__
bases
__}
The tuple of base classes of a class object.
\end{memberdescni}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment