| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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) | ||
| Original file line number | Diff line number | Diff 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) | ||
| Original file line number | Diff line number | Diff 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) | ||
| Original file line number | Diff line number | Diff 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) | ||
| Original file line number | Diff line number | Diff 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) | ||
| Original file line number | Diff line number | Diff 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 | + | ||
| Original file line number | Diff line number | Diff 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 | + | ||
| Original file line number | Diff line number | Diff 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() | ||
| Original file line number | Diff line number | Diff 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() | ||
| Original file line number | Diff line number | Diff 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) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments