addtition

This commit is contained in:
lda committed 2025-01-31 14:39:37 +07:00
1 parent c95c4b9148
commit d1a042206c
2 files changed
+248 -38

No files matched your search

+21
View File
@@ -710,3 +710,24 @@ lda1.lda_print_example_arg() # pylint: disable=no-member # ide freak out
# except for lda_set_example_arg # except for lda_set_example_arg
# dont do this, however, as ide will freak out. # dont do this, however, as ide will freak out.
"""so uh that was a bad example huh.
turning back to list. Now you know list is a kinda a class.
and class has methods. List also has some methods.
"""
copied_1_20 = one_to_20.copy() # this shallow copies
copied_1_20.append(21)
assert copied_1_20 != one_to_20
# if you have intellicode you can do ctrl + space to get that hints going.
"""
ah yes intellicode.
You can view methods easily with intellisense if using vscode,
and you can also docs.python.org for more
"""
+227 -38
View File
@@ -26,8 +26,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"x = 3 # variable = value\n", "x = 3 # variable = value\n",
"x = 31.28 # float value\n", "x = 31.28 # float value\n",
"\n", "\n",
"x = 3 + 5\n", "x = 3 + 5\n",
"assert x == 8" "assert x == 8"
@@ -44,29 +44,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"thats right\n"
]
}
],
"source": [ "source": [
"try:\n", "try:\n",
" x\n", " x\n",
"except NameError:\n", "except NameError: # last code block define x\n",
" print(\"play the last code block broski\")\n", " print(\"play the last code block broski\")\n",
"else:\n", "else: # last code block ran\n",
" print(\"thats right\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" x\n",
"except NameError:\n",
" print(\"play the last code block broski\")\n",
"else:\n",
" print(\"thats right\")" " print(\"thats right\")"
] ]
}, },
@@ -90,13 +84,9 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"my_list = [\"this\", \"is\", \"a\", \"list\"]\n", "my_list = [\"this\", \"is\", \"a\", \"list\"]\n",
"my_dict = {\n", "my_dict = {\"my key\": \"my value\", \"my life\": \"my rules\", \"my style\": \"my attitute\"}\n",
" \"my key\": \"my value\",\n",
" \"my life\": \"my rules\",\n",
" \"my style\": \"my attitute\"\n",
"}\n",
"\n", "\n",
"assert my_list[1] == \"is\" # not \"this\"\n", "assert my_list[1] == \"is\" # not \"this\"\n",
"assert my_list[-1] == \"list\"" "assert my_list[-1] == \"list\""
] ]
}, },
@@ -106,12 +96,12 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"my_longer = list(range(20)) # 0 -> 19\n", "my_longer = list(range(20)) # 0 -> 19\n",
"\n", "\n",
"assert my_longer[2:5] == [2, 3, 4] # slice\n", "assert my_longer[2:5] == [2, 3, 4] # slice\n",
"assert my_longer[:4] == [0, 1, 2, 3] # blank start for 0\n", "assert my_longer[:4] == [0, 1, 2, 3] # blank start for 0\n",
"assert my_longer[3::5] == [3, 8, 13, 18] # blank stop for past end\n", "assert my_longer[3::5] == [3, 8, 13, 18] # blank stop for past end\n",
"assert my_longer[18:6:-4] == [18, 14, 10] # empty/no step for 1\n", "assert my_longer[18:6:-4] == [18, 14, 10] # empty/no step for 1\n",
"assert my_longer[:-3:8] == [0, 8, 16]" "assert my_longer[:-3:8] == [0, 8, 16]"
] ]
}, },
@@ -126,7 +116,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -143,11 +133,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"my_function(\"hello \", \"world!\") # dont do this\n", "my_function(\"hello \", \"world!\") # dont do this\n",
"my_function(2, 6)" "my_function(2, 6)"
] ]
}, },
@@ -176,9 +177,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"34"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"container = [1, 11, 5, 17]\n", "container = [1, 11, 5, 17]\n",
"sum_ = 0\n", "sum_ = 0\n",
@@ -196,10 +208,187 @@
"x = 0\n", "x = 0\n",
"while True:\n", "while True:\n",
" x += 1\n", " x += 1\n",
" \n", "\n",
" if x > 20:\n", " if x > 20:\n",
" break" " break"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"match 2 + 3:\n",
" case x if x <= 4:\n",
" print(\"no way\")\n",
" case 5:\n",
" print(\"2 + 3 = 5\")\n",
" case x if x > 6: # match doesnt need to cover all cases\n",
" print(\"woah\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`break` and `continue` work with the innermost for/while loop. also works with match i think i never tested\n",
"\n",
"### Exceptions\n",
"\n",
"exceptions are python errors. you can let it crash, catch with try except, or raise one yourself.\n",
"\n",
"Some common ones are `ValueError` `TypeError` and `OSError` type shit"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" raise ValueError(\"value eroe\")\n",
"except ValueError as error:\n",
" print(\"raised\", error)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### class\n",
"\n",
"class. methods. backbone of python."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('spam', 42)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"class Foo:\n",
" bar = \"baz\"\n",
"\n",
" def quux(tis, arg1):\n",
" return arg1, 42\n",
" \n",
"# usage:\n",
"\n",
"fbar = Foo()\n",
"\n",
"fbar.quux(\"spam\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"looking ass.\n",
"\n",
"class has class properties and instance properties. instance probably goes self.something, while class Foo.something.\n",
"\n",
"it can be a number, a string, a list (not advised), or a function?\n",
"\n",
"for a function in a class it would be marked a classmethod (`@classmethod`) and with classmethods the instance get passed in first arg.\n",
"`@staticmethod` used in the class block revert this behavior.\n",
"\n",
"check the tutorial.py file im lazy"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, [10, 7, 4])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# everything is a class so your list is also a class\n",
"# so it has classmethods:\n",
"\n",
"list_lda = [1, 4, 7]\n",
"list_lda.append(10)\n",
"list_lda.reverse()\n",
"list_lda.pop(), list_lda"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"do research broski\n",
"\n",
"## what the fuck is this half code half document\n",
"\n",
"jupyter. very flexible very dynamic. you can have jupyter running on browser or on vscode i think\n",
"\n",
"jupyter has a lot of thingimajig suitable for data engineers.\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1 5 7]\n",
" [2 6 8]\n",
" [3 4 9]]\n"
]
}
],
"source": [
"try:\n",
" import numpy as np\n",
"except ImportError:\n",
" print(\"python -m pip install numpy\")\n",
"else:\n",
" print(np.array([[1, 5, 7], [2, 6, 8], [3, 4, 9]]))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"for example the shit we are very much working with in the course: numpy. matplotlib. scipy maybe\n",
"\n",
"### numpy\n",
"\n",
"so you just learned python. SCRAP ALL THAT SHIT we learn a new language called Numpy.\n",
"\n",
"fuck you mean numpy a new language?\n",
"\n",
"see. numpy dont use python for the bulk of its operations. python is slow, they say, but c is fast. numpy is made in C.\n",
"\n",
"so numpy dont use python types. numpy uses its own types. its own functions. almost all of them not from python but from C for all the speed\n",
"\n",
"try ctrl space the just imported np object. snoop around. its complicated. theres so much. we dont use much of it tho."
]
} }
], ],
"metadata": { "metadata": {