|
381 | 381 | "and avoid repeating code."
|
382 | 382 | ]
|
383 | 383 | },
|
| 384 | + { |
| 385 | + "cell_type": "code", |
| 386 | + "execution_count": 13, |
| 387 | + "metadata": {}, |
| 388 | + "outputs": [ |
| 389 | + { |
| 390 | + "name": "stdout", |
| 391 | + "output_type": "stream", |
| 392 | + "text": [ |
| 393 | + "010101010000111001 code go brrrrrr\n", |
| 394 | + "Treating a person...\n" |
| 395 | + ] |
| 396 | + } |
| 397 | + ], |
| 398 | + "source": [ |
| 399 | + "class ComputerScientist(Person):\n", |
| 400 | + " def __init__(self, name, age):\n", |
| 401 | + " super().__init__(name, age, \"computer scientist\")\n", |
| 402 | + " \n", |
| 403 | + " def write_code(self):\n", |
| 404 | + " print(\"010101010000111001 code go brrrrrr\")\n", |
| 405 | + " \n", |
| 406 | + "class Doctor(Person):\n", |
| 407 | + " def __init__(self, name, age):\n", |
| 408 | + " super().__init__(name, age, \"computer scientist\")\n", |
| 409 | + " \n", |
| 410 | + " def treat_person(self):\n", |
| 411 | + " print(\"Treating a person...\")\n", |
| 412 | + "\n", |
| 413 | + "donald_knuth = ComputerScientist(\"donald knuth\", 84)\n", |
| 414 | + "donald_knuth.write_code()\n", |
| 415 | + "\n", |
| 416 | + "doctor = Doctor(\"John Doe\", 65)\n", |
| 417 | + "doctor.treat_person()" |
| 418 | + ] |
| 419 | + }, |
384 | 420 | {
|
385 | 421 | "cell_type": "markdown",
|
386 | 422 | "metadata": {},
|
|
0 commit comments