Вы находитесь на странице: 1из 3

{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"JS-

01.ipynb","version":"0.3.2","provenance":[],"collapsed_sections":
[]},"language_info":{"codemirror_mode":
{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-
python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","
version":"3.7.1"},"kernelspec":{"display_name":"Python
3","language":"python","name":"python3"}},"cells":
[{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"6tm6mriXr58W","colab_type":"text"},"source":["# Python
Jumpstart\n","## Part 1\n","### Quick Review"]},{"cell_type":"markdown","metadata":
{"slideshow":
{"slide_type":"slide"},"id":"v24w5V6Kr58a","colab_type":"text"},"source":["###
History\n","### Why Python?\n","### Scalar Data Types\n","### Sequence Data
Types\n","### Basic I/O"]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"MBSZBTf2r58d","colab_type":"text"},"source":["###
Dynamically typed <=> Strongly typed\n","#### No variable declaration"]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"yam_kTcwr58g","colab_type":"code","colab":
{},"outputId":"6b064d65-8b48-4982-d870-b5f672031409"},"source":["a = 17\n","b
= \"Hello\"\n","c = a + b"],"execution_count":0,"outputs":
[{"output_type":"error","ename":"TypeError","evalue":"unsupported operand type(s)
for +: 'int' and 'str'","traceback":
["\u001b[0;31m---------------------------------------------------------------------
------\u001b[0m","\u001b[0;31mTypeError\u001b[0m
Traceback (most recent call last)","\u001b[0;32m<ipython-input-1-
7b8d318e7389>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m
1\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m
\u001b[0;36m17\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[
1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m
\u001b[0;34m\"Hello\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n
\u001b[0;32m----> 3\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m
\u001b[0ma\u001b[0m \u001b[0;34m+\u001b[0m
\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and
'str'"]}]},{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"Xz1wJBmPr58x","colab_type":"code","colab":
{},"outputId":"c52c7d2d-51de-4886-f590-f31bf0041970"},"source":["c = a +
d"],"execution_count":0,"outputs":
[{"output_type":"error","ename":"NameError","evalue":"name 'd' is not
defined","traceback":
["\u001b[0;31m---------------------------------------------------------------------
------\u001b[0m","\u001b[0;31mNameError\u001b[0m
Traceback (most recent call last)","\u001b[0;32m<ipython-input-2-
a768ab610d41>\u001b[0m in
\u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m
\u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m
\u001b[0;34m+\u001b[0m
\u001b[0md\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'd' is not defined"]}]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"TOYZ_UUNr587","colab_type":"text"},"source":["###
Scalar Data Types\n","\n"," * Integers\n"," * Floats\n"," * Booleans\n"," *
Complex"]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"iKz8llJRr589","colab_type":"text"},"source":["####
Integers\n"," * No limit\n"," * Usual operators: + PLUS, - MINUS, * STAR and %
PERCENTAGE\n"," * Different operators: \n"," - / SLASH for floating
division\n"," - // DOUBLE SLASH for truncating division\n"," - ** DOUBLE
STAR for exponentiation\n"," * assignment operators\n"," - x ⊙= y ⇨ x = x ⊙
y"]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"TncILjmqr59A","colab_type":"text"},"source":["####
Floats\n"," * Same as C double!\n"," * With the usual troubles"]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"TFmKiVuhr59D","colab_type":"code","colab":
{},"outputId":"a2a862f1-f357-47b4-bfca-fdd1af27fa35"},"source":["x = 12.9\n","y =
3.6\n","print(x * y)"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["46.440000000000005\n"],"name":"stdout"}]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"oAbt4F8Gr59M","colab_type":"text"},"source":["####
Booleans\n"," * True\n"," * False\n"," * Usual operators:\n"," - ==, !
=\n"," - <, <=, >, >=\n"," * Additionally, \n"," - 0 < க < 9\n"," - 0
< க < வ < 12\n"," "]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"ralpHop3r59O","colab_type":"text"},"source":["####
Complex\n"," * uses j for $\\sqrt{-1}$ 😠\n"," "]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"I86iN_JBr59R","colab_type":"code","colab":
{},"outputId":"883b2787-92e6-43e9-9e0a-effc9f635738"},"source":["α = 7.1 +
4.3j\n","β = -2.5 + 6.4j\n","γ = α + β\n","print(γ)\n","print(α *
β)"],"execution_count":0,"outputs":[{"output_type":"stream","text":
["(4.6+10.7j)\n","(-45.269999999999996+34.69j)\n"],"name":"stdout"}]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"3Wwqfeglr59a","colab_type":"text"},"source":["##
Sequence data types\n"," * Lists\n"," * Strings\n"," * Tuples\n"," *
Arrays?"]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"vTYidNOir59c","colab_type":"text"},"source":["###
Lists\n"," * Standard heterogenous collection\n"," * enclosed within []'s\n"," *
accessed using [index] notation\n"," - indices: 0 .. size-1\n"," - negative
indices\n"," * rich set of operations\n"," - append(), extend(), insert()\n","
- remove(), pop()\n"," - in, index(), count()\n"," - be careful about the
mutators: sort(), reverse()"]},{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"BqRhznuKr59f","colab_type":"code","colab":
{},"outputId":"dc92959c-66a7-4b26-e8ab-c3c7f677d31d"},"source":["a = [1, 3, 2,
4]\n","print(1 in a)\n","print(5 in a)\n","a =
a.sort()\n","print(a)"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["True\n","False\n","None\n"],"name":"stdout"}]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"AsiuTM8Ir59o","colab_type":"code","colab":
{},"outputId":"4938542e-564f-423d-f431-03a226d50398"},"source":["a = [1, 3, 2,
4]\n","a.sort()\n","print(a)"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["[1, 2, 3, 4]\n"],"name":"stdout"}]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"n39gm-8yr59x","colab_type":"text"},"source":["####
Implementation note\n"," * contiguous arrays of pointers--dynamically grown\n","
* append(), pop() are fast\n"," * insert() and pop(i) are slow"]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"eISNowOJr590","colab_type":"text"},"source":["###
Strings\n"," - Can be single quoted\n"," - Or double quoted!\n"," - Or triple
quoted!!\n"," * with single quotes\n"," * or double quotes\n"," -
IMMUTABLE\n"," - \\+ for concatenation\n"," - \\* for repetition"]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"subslide"},"id":"VEeo6S2br592","colab_type":"code","colab":
{}},"source":["a = \"Hello World!\"\n","b = \"I'm happy to use Python\"\n","c =
'GvR says, \"Readability counts\" and Python shines here'\n","d = \"\"\" Long long
ago, in a galaxy far far away ...\n"," It is a period of civil war. Rebel
spaceships, striking from a hidden\n"," base, have won their first victory
against the evil Galactic Empire. \n"," During the battle, Rebel spies managed
to steal secret plans to the\n"," Empire’s ultimate weapon, the DEATH STAR, an
armored space station \n"," with enough power to destroy an entire planet.
….\"\"\""],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":
{"slideshow":
{"slide_type":"slide"},"id":"qMTDMpuPr599","colab_type":"text"},"source":["####
String methods\n"," * lower(), upper(), title(), capitalize(), swapcase()\n"," *
in, startsWith(), endsWith()\n"," * find(), index(), count()\n"," * just(),
center()\n"," * split(), join()\n"," * strip()\n"," * translate(), encode()\n","
* is...()\n"," * Formatting"]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"rnh8MrYrr59_","colab_type":"text"},"source":["###
Slicing and Striding\n"]},{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"TZWtHQ00r5-B","colab_type":"code","colab":
{},"outputId":"679a40db-ff75-4958-d47c-25205466c84e"},"source":["f = [0, 1, 1, 2,
3, 5, 8, 13, 21,
34]\n","print(f[3:6])\n","print(f[:7])\n","print(f[5:])\n","print(f[1:-
1])"],"execution_count":0,"outputs":[{"output_type":"stream","text":["[2, 3,
5]\n","[0, 1, 1, 2, 3, 5, 8]\n","[5, 8, 13, 21, 34]\n","[1, 1, 2, 3, 5, 8, 13,
21]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"Syd5g9fer5-L","colab_type":"code","colab":
{},"outputId":"ee25fc86-6f1a-4c36-dca6-6242a49295be"},"source":
["print(f[1::3])\n","print(f[::2])\n","print(f[::-
1])"],"execution_count":0,"outputs":[{"output_type":"stream","text":["[1, 3,
13]\n","[0, 1, 3, 8, 21]\n","[34, 21, 13, 8, 5, 3, 2, 1, 1,
0]\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"jCwt2_amr5-U","colab_type":"text"},"source":["###
Tuples\n"," * Immutable, heterogenous\n"," * Best thought of as
records/structures\n"," * enclosed in parentheses\n"," * separated by comma\n","
* auto packing and unpacking"]},{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"slide"},"id":"Ert3zFwBr5-Y","colab_type":"code","colab":
{},"outputId":"6f7ace2f-a496-46b7-b3c3-aa79dc8abe46"},"source":["a
= 17\n","b = 23\n","a, b = b, a\n","print(a, b)"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["23 17\n"],"name":"stdout"}]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"2K24zgcdr5-n","colab_type":"code","colab":
{},"outputId":"b8ad6157-74e0-4805-deb2-061ec18cddcc"},"source":["α
= \"Hello\"\n","β = \"World!\"\n","க = 42 \n","α, β = β, α\n","print(α, β)\n","க, β
= β, க\n","print(க, β)"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["World! Hello\n","Hello 42\n"],"name":"stdout"}]},
{"cell_type":"code","metadata":{"slideshow":
{"slide_type":"fragment"},"id":"vHgOuLr5r5-z","colab_type":"code","colab":
{},"outputId":"593b3480-6616-464a-d9ae-4238d428f508"},"source":["a, b, n = 12, 10,
0\n","x = (12, 10, 0)\n","print(x[0])"],"execution_count":0,"outputs":
[{"output_type":"stream","text":["12\n"],"name":"stdout"}]},
{"cell_type":"markdown","metadata":{"slideshow":
{"slide_type":"slide"},"id":"tmYInD9tr5_B","colab_type":"text"},"source":["###
Simple Input Output\n"," * input() for reading from stdin\n"," - can take a
prompt\n"," * print() for writing to stdout\n"," * print() + string
formatting"]}]}

Вам также может понравиться