From 9be7c7087fd4160e1fa63718b2f07b6ececf96d4 Mon Sep 17 00:00:00 2001 From: Matheus Felipe <50463866+matheusfelipeog@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:41:22 -0300 Subject: [PATCH] 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. --- python.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/python.md b/python.md index 8ab16bb..9ce7f80 100644 --- a/python.md +++ b/python.md @@ -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) ```