Skip to content

Commit

Permalink
Merge pull request #2992 from enkidevs/classes-i
Browse files Browse the repository at this point in the history
Classes i
  • Loading branch information
Stefan-Stojanovic authored Jan 14, 2022
2 parents f4139f3 + 18607f2 commit 8b972b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Types of change:
### Changed
- [Html - Link Relative Paths - Change part of PQ as it wasn't worder properly](https://github.com/enkidevs/curriculum/pull/2985)
- [Python - Format Text Paragraphs With Textwrap - Make the fill method more clear](https://github.com/enkidevs/curriculum/pull/2981)
- [Python - Classes I - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/2992)
- [Python - Looping - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3000)
- [Python - Meet Python - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3003)
- [Python - Python Tips - Move single-line commands to a single line, update indentation in codeblocks from 4 to 2 spaces](https://github.com/enkidevs/curriculum/pull/3010)
Expand Down
10 changes: 5 additions & 5 deletions python/python-core/classes-i/class-keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Functions inside any object type are known as *methods* (the case for class func
```python
# a data structure
class Employee:
# an attribute
count = 5
# a method
def print_idnum(self):
...
# an attribute
count = 5
# a method
def print_idnum(self):
...
```


Expand Down
5 changes: 2 additions & 3 deletions python/python-core/classes-i/creating-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Classes are defined with the `class` keyword and use Python's block structure[2]

```python
class Employee:
count = 0
count = 0
```

To create an instance of a class (also called to "instantiate") is done like so:
Expand Down Expand Up @@ -61,8 +61,7 @@ Once the `__init__` method has been taken care of, other methods can be defined
class Employee:
# the code above
def print_idnum(self):
print("{0} is employee no. {1}"
.format(self.name, self.idnum))
print("{0} is employee no. {1}".format(self.name, self.idnum))
```

> 💡 On the other hand, when calling methods, you do not need to pass `self` as a parameter, Python does that for you automatically.
Expand Down
16 changes: 8 additions & 8 deletions python/python-core/classes-i/method-overriding.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ To *override* a parent method, the child class should define a method with the *

```python
class Animal:
def identify(self):
print("I am an animal")
def identify(self):
print("I am an animal")

class Bird(Animal):
def identify(self):
print("I am a bird")
def identify(self):
print("I am a bird")

bird = Bird()
bird.identify()
Expand All @@ -58,10 +58,10 @@ To add some behavior to a method but also use the parent method behavior, use `s
# No changes made to the class Animal
# Change class Bird to:
class Bird(Animal):
def identify(self):
# added line, calls parent method
super().identify()
print("I am a bird")
def identify(self):
# added line, calls parent method
super().identify()
print("I am a bird")

bird = Bird()
bird.identify()
Expand Down
6 changes: 2 additions & 4 deletions python/python-core/classes-i/using-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class Employee:
self.name = name
self.idnum = Employee.count
def print_idnum(self):
print("{0} is employee no. {1}"
.format(self.name, self.idnum))
print("{0} is employee no. {1}".format(self.name, self.idnum))
```

To create an instance of the class:
Expand Down Expand Up @@ -67,8 +66,7 @@ class Employee:
self.name = name
self.idnum = Employee.count
def print_idnum(self):
print("{0} is employee no. {1}"
.format(self.name, self.idnum))
print("{0} is employee no. {1}".format(self.name, self.idnum))

steve = ???('???')
```
Expand Down

0 comments on commit 8b972b4

Please sign in to comment.