You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- {doc}`Getting Started <../introduction/getting_started>`
@@ -637,7 +640,7 @@ We are used to defining variables like `x = dict("a": 1, "b": 2)` and then using
637
640
For example, a simple class that stores two variables would look like this:
638
641
639
642
```{code-cell} python
640
-
class A:
643
+
class MyType:
641
644
def __init__(self, x, y):
642
645
self.x = x
643
646
self.y = y
@@ -648,13 +651,13 @@ Used both internal and external to classes, the `__init__` method is a special m
648
651
A class, defined by the `class` keyword, is a blueprint for an object. It defines the attributes and methods that an object will have. An object is an instance of a class that has been created and assigned to a variable. It is created by calling the class name as if it were a function. When you call the class name, the object is created and the `__init__` method is called by default.
649
652
650
653
```{code-cell} python
651
-
a = A(1, 2)
652
-
b = A(3, 4)
653
-
# Notice that these are different objects
654
+
a = MyType(1, 2)
655
+
b = MyType(3, 4)
656
+
# Notice that these are different objects, even though they are the same type!
654
657
a == b
655
658
```
656
659
657
-
You can see that `a` and `b` are both instances of the `A` class by using the `type` function.
660
+
You can see that `a` and `b` are both instances of the `MyType` class by using the `type` function.
658
661
659
662
```{code-cell} python
660
663
type(a)
@@ -670,7 +673,7 @@ In addition to attributes, objects can also have methods. Methods are functions
670
673
671
674
672
675
```{code-cell} python
673
-
class B:
676
+
class MyAdder:
674
677
def __init__(self, x, y):
675
678
self.x = x
676
679
self.y = y
@@ -679,10 +682,10 @@ class B:
679
682
return self.x + self.y
680
683
```
681
684
682
-
We can now create an object of type `B` and call the `add` method, in the same way that we called methods on built-in types (like the `.upper()` method on a string.)
685
+
We can now create an object of type `MyAdder` and call the `add` method, in the same way that we called methods on built-in types (like the `.upper()` method on a string.)
0 commit comments