Fixes in Python Classes & Inheritance

Fixes:
- Remove docstring from the class definition. This makes no sense for the example;
- Fix indentation in Constructors;
- Fix indentation in Method;
- Fix class name in Class Variables;
- Fix examples in Class Variables. The old one did not correspond to class variables.
This commit is contained in:
Matheus Felipe authored and GitHub committed 2022-02-06 18:41:22 -03:00
1 parent e2aee30178
commit 9be7c7087f
1 file changed
+8 -10
+8 -10
View File
@@ -1061,7 +1061,6 @@ Python Classes & Inheritance {.cols-3}
```python
class MyNewClass:
'''This is a docstring.'''
pass
# Class Instantiation
@@ -1075,7 +1074,7 @@ my = MyNewClass()
```python
class Animal:
def __init__(self, voice):
self.voice = voice
self.voice = voice
cat = Animal('Meow')
print(cat.voice) # => Meow
@@ -1092,7 +1091,7 @@ class Dog:
# Method of the class
def bark(self):
print("Ham-Ham")
print("Ham-Ham")
charlie = Dog()
charlie.bark() # => "Ham-Ham"
@@ -1103,17 +1102,16 @@ charlie.bark() # => "Ham-Ham"
### Class Variables {.row-span-2}
```python
class my_class:
class MyClass:
class_variable = "A class variable!"
x = my_class()
y = my_class()
# => A class variable!
print(MyClass.class_variable)
x = MyClass()
# => A class variable!
print(x.class_variable)
# => A class variable!
print(y.class_variable)
```