summaryrefslogtreecommitdiffstats
path: root/Doc/tutorial/classes.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tutorial/classes.rst')
-rw-r--r--Doc/tutorial/classes.rst9
1 files changed, 8 insertions, 1 deletions
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index d82adf6..b1f3f00 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -210,6 +210,7 @@ definition looked like this::
class MyClass:
"""A simple example class"""
i = 12345
+
def f(self):
return 'hello world'
@@ -458,8 +459,10 @@ variable in the class is also ok. For example::
class C:
f = f1
+
def g(self):
return 'hello world'
+
h = g
Now ``f``, ``g`` and ``h`` are all attributes of class :class:`C` that refer to
@@ -473,8 +476,10 @@ argument::
class Bag:
def __init__(self):
self.data = []
+
def add(self, x):
self.data.append(x)
+
def addtwice(self, x):
self.add(x)
self.add(x)
@@ -670,7 +675,7 @@ will do nicely::
class Employee:
pass
- john = Employee() # Create an empty employee record
+ john = Employee() # Create an empty employee record
# Fill the fields of the record
john.name = 'John Doe'
@@ -796,8 +801,10 @@ defines :meth:`~iterator.next`, then :meth:`__iter__` can just return ``self``::
def __init__(self, data):
self.data = data
self.index = len(data)
+
def __iter__(self):
return self
+
def next(self):
if self.index == 0:
raise StopIteration