FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Updated · bytecodeman/PythonForJavaDevs@8ee55cf · GitHub

Repository navigation

Commit 8ee55cf

Browse files
authored andcommitted
Updated
1 parent b1b5e38 commit 8ee55cf

21 files changed

Lines changed: 177 additions & 0 deletions

File tree

‎045 Raising Exceptions/raising.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class MyException(Exception):
2+
pass
3+
4+
try:
5+
raise MyException("Oh no!")
6+
except MyException as e:
7+
print(e)

‎046 Asssertions/assertions.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
value = 7
3+
4+
try:
5+
assert value > 8, "Oh no!"
6+
except AssertionError as a:
7+
print(a)

‎047 Classes/classes.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Person:
2+
def eating(self):
3+
print("I'm eating!")
4+
5+
p = Person()
6+
p.eating()
7+
print(p)

‎048 Constructors/constructors.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Person:
2+
def __init__(self, name):
3+
self._name = name
4+
5+
def eating(self):
6+
print(f"{self._name} is eating!")
7+
8+
p = Person("Bob")
9+
p.eating()
10+
print(p)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Person:
2+
def __init__(self, name):
3+
self._name = name
4+
5+
def eating(self):
6+
print(f"{self._name} is eating!")
7+
8+
def __str__(self):
9+
return f"Hello I am {self._name}"
10+
11+
p = Person("Bob")
12+
p.eating()
13+
print(p)
14+
15+
text = str(p)
16+
print(text)

‎050 Eval and Repr/rep.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Person:
2+
def __init__(self, name):
3+
self._name = name
4+
5+
def eating(self):
6+
print(f"{self._name} is eating!")
7+
8+
def __str__(self):
9+
return f"Hello I am {self._name}"
10+
11+
def __repr__(self):
12+
return f'Person("{self._name}")'
13+
14+
p = Person("Bob")
15+
p.eating()
16+
print(p)
17+
18+
text = str(p)
19+
print(text)
20+
21+
print(eval(repr(p)))
22+

‎051 Inheritance/inherit.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Person:
2+
def __init__(self, name):
3+
self._name = name
4+
5+
def eating(self):
6+
print(f"{self._name} is eating!")
7+
8+
def __str__(self):
9+
return f"Hello I am {self._name}"
10+
11+
def __repr__(self):
12+
return f'Person("{self._name}")'
13+
14+
class Employee(Person):
15+
def go_on_holiday(self):
16+
print("I'm going on holiday!")
17+
18+
p = Person("Bob")
19+
e = Employee("Sue")
20+
e.eating()
21+
e.go_on_holiday()
22+
23+

‎052 Overriding Methods/override.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Animal:
2+
def speak(self):
3+
print("I'm an animal")
4+
5+
class Cat(Animal):
6+
def speak(self):
7+
print("Meeouw")
8+
9+
cat = Cat()
10+
cat.speak()

‎053 Super/super.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Machine:
2+
def __init__(self):
3+
print("Machine constructor")
4+
5+
class Car(Machine):
6+
def __init__(self):
7+
super().__init__()
8+
print("Car constructor")
9+
10+
c = Car()

‎054 Class Attributes/classattr.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Machine:
2+
3+
count = 0
4+
5+
def __init__(self):
6+
Machine.count += 1
7+
8+
Machine()
9+
Machine()
10+
print(Machine.count)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL