diff --git a/Classes and objects/Special __init__ method/task.md b/Classes and objects/Special __init__ method/task.md index 0aedd74..3790a61 100644 --- a/Classes and objects/Special __init__ method/task.md +++ b/Classes and objects/Special __init__ method/task.md @@ -23,13 +23,13 @@ The `__init__()` method may receive arguments for greater flexibility. In that case, arguments given to the class instantiation operator are passed on to `__init__()`. For example: ```python -class Complex: +class ComplexNumber: def __init__(self, real_part, imag_part): self.r = real_part self.i = imag_part self.num = complex(self.r, self.i) -x = Complex(3.0, -4.5) # Instantiating a complex number +x = ComplexNumber(3.0, -4.5) # Instantiating a complex number x.num ``` ```text diff --git a/Classes and objects/The self parameter/self_parameter.py b/Classes and objects/The self parameter/self_parameter.py index 2e5d59e..b87f461 100644 --- a/Classes and objects/The self parameter/self_parameter.py +++ b/Classes and objects/The self parameter/self_parameter.py @@ -1,5 +1,5 @@ -class Complex: - def create(self, real_part, imag_part): +class ComplexBuilder: + def set_parts(self, real_part, imag_part): self.r = real_part self.i = imag_part @@ -7,8 +7,8 @@ def build(self): self.num = complex(self.r, self.i) -complex_number = Complex() # Instantiate a complex number object -complex_number.create(12, 5) # Call create method with real_part = 12 and imag_part = 5 +complex_number = ComplexBuilder() # Instantiate a complex number object +complex_number.set_parts(12, 5) # Call set_parts method with real_part = 12 and imag_part = 5 complex_number.build() # Build the complex number print(complex_number.num) diff --git a/Classes and objects/The self parameter/task-info.yaml b/Classes and objects/The self parameter/task-info.yaml index f9ce016..e6b9402 100644 --- a/Classes and objects/The self parameter/task-info.yaml +++ b/Classes and objects/The self parameter/task-info.yaml @@ -3,10 +3,10 @@ files: - name: self_parameter.py visible: true placeholders: - - offset: 484 + - offset: 507 length: 22 placeholder_text: "# Update the current attribute by adding the amount to it." - - offset: 550 + - offset: 573 length: 12 placeholder_text: ??? - name: tests/__init__.py diff --git a/Classes and objects/__str__ vs __repr__/str_and_repr.py b/Classes and objects/__str__ vs __repr__/str_and_repr.py index c0a2ecc..1d65dd2 100644 --- a/Classes and objects/__str__ vs __repr__/str_and_repr.py +++ b/Classes and objects/__str__ vs __repr__/str_and_repr.py @@ -1,16 +1,16 @@ -class Complex: +class ComplexNumber: def __init__(self, real_part, imag_part): self.real = real_part self.img = imag_part def __repr__(self): - return f'Complex({self.real}, {self.img})' + return f'ComplexNumber({self.real}, {self.img})' def __str__(self): return f'{self.real} + i{self.img}' -x = Complex(2, 5) +x = ComplexNumber(2, 5) print(str(x)) print(repr(x)) diff --git a/Classes and objects/__str__ vs __repr__/task-info.yaml b/Classes and objects/__str__ vs __repr__/task-info.yaml index 19b7d98..a84975e 100644 --- a/Classes and objects/__str__ vs __repr__/task-info.yaml +++ b/Classes and objects/__str__ vs __repr__/task-info.yaml @@ -3,10 +3,10 @@ files: - name: str_and_repr.py visible: true placeholders: - - offset: 455 + - offset: 473 length: 46 placeholder_text: ??? - - offset: 541 + - offset: 559 length: 45 placeholder_text: ??? - name: tests/__init__.py diff --git a/Classes and objects/__str__ vs __repr__/task.md b/Classes and objects/__str__ vs __repr__/task.md index 5eb5b0e..704f724 100644 --- a/Classes and objects/__str__ vs __repr__/task.md +++ b/Classes and objects/__str__ vs __repr__/task.md @@ -24,7 +24,7 @@ defined in the object's class. Our own defined class should therefore have a `__repr__` if we need detailed information for debugging. Also, if we think it would be useful to have a string representation for users, we should create -a `__str__` function. Check out another implementation of the class `Complex` in the code editor. Run the code +a `__str__` function. Check out another implementation of the class `ComplexNumber` in the code editor. Run the code to see what each of the two `print` statements prints. For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7139#str__-vs-__repr?utm_source=jba&utm_medium=jba_courses_links).