Skip to content

Instantly share code, notes, and snippets.

@ischurov
Created February 5, 2021 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ischurov/72f5dd2e89b9e16e3f3b4bf43ae2fb94 to your computer and use it in GitHub Desktop.
Save ischurov/72f5dd2e89b9e16e3f3b4bf43ae2fb94 to your computer and use it in GitHub Desktop.
lesson08.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "## Объекты и классы"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, name):\n self.name = name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")",
"execution_count": 11,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(\"Alice\")",
"execution_count": 12,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.name",
"execution_count": 13,
"outputs": [
{
"data": {
"text/plain": "'Alice'"
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "type(alice)",
"execution_count": 14,
"outputs": [
{
"data": {
"text/plain": "__main__.Person"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.say_hello()",
"execution_count": 15,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Hello, my name is Alice.\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name",
"execution_count": 16,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(first_name=\"Alice\", last_name=\"Smith\")\nassert alice.full_name() == \"Alice Smith\"",
"execution_count": 17,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.full_name()",
"execution_count": 19,
"outputs": [
{
"data": {
"text/plain": "'Alice Smith'"
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(alice)",
"execution_count": 20,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "<__main__.Person object at 0x7fd405cba7b8>\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 21,
"outputs": [
{
"data": {
"text/plain": "<__main__.Person at 0x7fd405cba7b8>"
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()",
"execution_count": 22,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(first_name=\"Alice\", last_name=\"Smith\")",
"execution_count": 23,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(alice)",
"execution_count": 24,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Alice Smith\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "str(alice)",
"execution_count": 25,
"outputs": [
{
"data": {
"text/plain": "'Alice Smith'"
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 26,
"outputs": [
{
"data": {
"text/plain": "<__main__.Person at 0x7fd405ea5a58>"
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "s = \"Hello\\nWorld\"",
"execution_count": 28,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(s)",
"execution_count": 29,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Hello\nWorld\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(repr(s))",
"execution_count": 30,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "'Hello\\nWorld'\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "s",
"execution_count": 31,
"outputs": [
{
"data": {
"text/plain": "'Hello\\nWorld'"
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(12)\nprint(\"12\")",
"execution_count": 33,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "12\n12\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(repr(12))\nprint(repr(\"12\"))",
"execution_count": 34,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "12\n'12'\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 35,
"outputs": [
{
"data": {
"text/plain": "<__main__.Person at 0x7fd405ea5a58>"
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "(\"abc\" \"def\")",
"execution_count": 39,
"outputs": [
{
"data": {
"text/plain": "'abcdef'"
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name={repr(self.first_name)}, \"\n f\"last_name={repr(self.last_name)})\"\n )",
"execution_count": 40,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(first_name=\"Alice\", last_name=\"Smith\")",
"execution_count": 41,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 42,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Alice', last_name='Smith')"
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice_copy = Person(first_name=\"Alice\", last_name=\"Smith\")",
"execution_count": 44,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice_copy",
"execution_count": 45,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Alice', last_name='Smith')"
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name={(self.first_name)}, \" f\"last_name={(self.last_name)})\"\n )",
"execution_count": 46,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(first_name=\"Alice\", last_name=\"Smith\")",
"execution_count": 47,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 48,
"outputs": [
{
"data": {
"text/plain": "Person(first_name=Alice, last_name=Smith)"
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Person(first_name=\"Alice\", last_name=\"Smith\")",
"execution_count": 49,
"outputs": [
{
"ename": "NameError",
"evalue": "name 'Alice' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-49-36cc622ab35b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mPerson\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfirst_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mAlice\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlast_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mSmith\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'Alice' is not defined"
]
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name='{(self.first_name)}', \"\n f\"last_name='{(self.last_name)}')\"\n )",
"execution_count": 50,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(\"Alice\", \"Smith\")",
"execution_count": 51,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 52,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Alice', last_name='Smith')"
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "oconnel = Person(\"Dan\", \"O'Connel\")",
"execution_count": 53,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "oconnel",
"execution_count": 54,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Dan', last_name='O'Connel')"
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Person(first_name='Dan', last_name='O'Connel')",
"execution_count": 55,
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-55-23bb5e3770c3>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-55-23bb5e3770c3>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m Person(first_name='Dan', last_name='O'Connel')\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name={repr(self.first_name)}, \"\n f\"last_name={repr(self.last_name)})\"\n )",
"execution_count": 56,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "oconnel = Person(\"Dan\", \"O'Connel\")",
"execution_count": 57,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "oconnel",
"execution_count": 58,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Dan', last_name=\"O'Connel\")"
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n self.friends = []\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name={repr(self.first_name)}, \"\n f\"last_name={repr(self.last_name)})\"\n )\n\n def show_friends(self):\n for friend in self.friends:\n print(friend)\n\n def add_friend(self, other):\n \"\"\"\n Add object other to list of my own friends\n Add myself to the list of other's friends\n \"\"\"\n self.friends.append(other)\n other.friends.append(self)",
"execution_count": 60,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(\"Alice\", \"Smith\")\nbob = Person(\"Bob\", \"Johnson\")\nalice.add_friend(bob)\nassert bob.friends == [alice]\nassert alice.friends == [bob]",
"execution_count": 61,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.show_friends()",
"execution_count": 62,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Bob Johnson\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "bob.show_friends()",
"execution_count": 63,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Alice Smith\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.add_friend(bob)",
"execution_count": 64,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 65,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Alice', last_name='Smith')"
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.show_friends()",
"execution_count": 66,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Bob Johnson\nBob Johnson\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.add_friend(alice)",
"execution_count": 67,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice",
"execution_count": 68,
"outputs": [
{
"data": {
"text/plain": "Person(first_name='Alice', last_name='Smith')"
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.show_friends()",
"execution_count": 69,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Bob Johnson\nBob Johnson\nAlice Smith\nAlice Smith\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "{\"a\": 2, \"b\": 3}",
"execution_count": 82,
"outputs": [
{
"data": {
"text/plain": "{'a': 2, 'b': 3}"
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "{\"a\", \"b\", 2}",
"execution_count": 83,
"outputs": [
{
"data": {
"text/plain": "{2, 'a', 'b'}"
},
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "type({})",
"execution_count": 85,
"outputs": [
{
"data": {
"text/plain": "dict"
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "set()",
"execution_count": 86,
"outputs": [
{
"data": {
"text/plain": "set()"
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class Person:\n # конструктор\n def __init__(self, first_name, last_name):\n self.first_name = first_name\n self.last_name = last_name\n self.friends = set()\n\n def say_hello(self):\n print(f\"Hello, my name is {self.name}.\")\n\n ### Написать функцию, которая будет возвращать полное имя (Имя Фамилия)\n def full_name(self):\n return self.first_name + \" \" + self.last_name\n\n def __str__(self):\n return self.full_name()\n\n def __repr__(self):\n return (\n f\"Person(first_name={repr(self.first_name)}, \"\n f\"last_name={repr(self.last_name)})\"\n )\n\n def show_friends(self):\n for friend in self.friends:\n print(friend)\n\n def add_friend(self, other):\n \"\"\"\n Add object other to list of my own friends\n Add myself to the list of other's friends\n \"\"\"\n if self is not other:\n self.friends.add(other)\n other.friends.add(self)",
"execution_count": 87,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a = [1, 2]\nb = [1, 2]\nc = a",
"execution_count": 71,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a == b",
"execution_count": 72,
"outputs": [
{
"data": {
"text/plain": "True"
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a == c",
"execution_count": 73,
"outputs": [
{
"data": {
"text/plain": "True"
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a is b",
"execution_count": 74,
"outputs": [
{
"data": {
"text/plain": "False"
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "a is c",
"execution_count": 75,
"outputs": [
{
"data": {
"text/plain": "True"
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(\"Alice\", \"Smith\")\nalso_alice = Person(\"Alice\", \"Smith\")",
"execution_count": 76,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice == also_alice",
"execution_count": 77,
"outputs": [
{
"data": {
"text/plain": "False"
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice is also_alice",
"execution_count": 78,
"outputs": [
{
"data": {
"text/plain": "False"
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice = Person(\"Alice\", \"Smith\")\nbob = Person(\"Bob\", \"Johnson\")",
"execution_count": 89,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.add_friend(bob)\nalice.add_friend(bob)\nalice.add_friend(alice)",
"execution_count": 90,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "alice.show_friends()",
"execution_count": 91,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Bob Johnson\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "bob.show_friends()",
"execution_count": 92,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Alice Smith\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "class MyNumber:\n def __init__(self, value):\n self.value = value\n\n def __repr__(self):\n return f\"MyNumber({repr(self.value)})\"\n\n def __str__(self):\n return f\"<{self.value}>\"\n\n def __add__(self, other):\n if not isinstance(other, MyNumber):\n other = MyNumber(other)\n return MyNumber(self.value * other.value)\n\n def __del__(self):\n print(f\"Oh, no! I'm object {repr(self)}. They are deleting me! Heeeeelp!!!\")",
"execution_count": 113,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(MyNumber(12))",
"execution_count": 114,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "<12>\nOh, no! I'm object MyNumber(12). They are deleting me! Heeeeelp!!!\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(MyNumber(3) + MyNumber(5))",
"execution_count": 108,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Oh, no! They are deleting me! Heeeeelp!!!\nOh, no! They are deleting me! Heeeeelp!!!\n<15>\nOh, no! They are deleting me! Heeeeelp!!!\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x = MyNumber(10)",
"execution_count": 109,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "del x",
"execution_count": 110,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Oh, no! They are deleting me! Heeeeelp!!!\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x",
"execution_count": 111,
"outputs": [
{
"ename": "NameError",
"evalue": "name 'x' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-111-6fcf9dfbd479>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'x' is not defined"
]
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "MyNumber(10) + 3 + 2 + 5 + 4 + 3",
"execution_count": 115,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Oh, no! I'm object MyNumber(3). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(10). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(2). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(30). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(5). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(60). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(4). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(300). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(3). They are deleting me! Heeeeelp!!!\nOh, no! I'm object MyNumber(1200). They are deleting me! Heeeeelp!!!\n"
},
{
"data": {
"text/plain": "MyNumber(3600)"
},
"execution_count": 115,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "2 + 5",
"execution_count": 116,
"outputs": [
{
"data": {
"text/plain": "7"
},
"execution_count": 116,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.10",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "lesson08.ipynb",
"public": false
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment