Created
January 26, 2022 16:50
-
-
Save ischurov/d85532d66e963e35bf6b7fe08810b42a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "formal-hacker", | |
| "metadata": {}, | |
| "source": [ | |
| "## Наука о данных\n", | |
| "### Совместный бакалавриат ВШЭ-РЭШ, 2021-2022 учебный год\n", | |
| "_Илья Щуров_\n", | |
| "\n", | |
| "[Страница курса](http://math-info.hse.ru/s21/j)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "moving-stupid", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "123" | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "s = \"123\"\n", | |
| "int(s)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "entertaining-requirement", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "False" | |
| ] | |
| }, | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool(0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "fifty-excess", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool(123)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "id": "outdoor-sensitivity", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool(\"True\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "id": "necessary-lotus", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool(\"False\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "id": "sensitive-target", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "False" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool(\"\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "id": "toxic-reason", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter word\n", | |
| "That's empty!\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "s = input(\"Enter word\")\n", | |
| "if s == \"\":\n", | |
| " print(\"That's empty!\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "id": "empty-saturday", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter word\n", | |
| "That's empty!\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "s = input(\"Enter word\")\n", | |
| "if not s:\n", | |
| " print(\"That's empty!\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 16, | |
| "id": "toxic-analysis", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter some words, separated by whitespase: \n", | |
| "We have no words!\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "s = input(\"Enter some words, separated by whitespase: \")\n", | |
| "words = s.split()\n", | |
| "if len(words) > 0:\n", | |
| " print(\"We have several words\")\n", | |
| "else:\n", | |
| " print(\"We have no words!\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 17, | |
| "id": "focal-salem", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter some words, separated by whitespase: hello\n", | |
| "We have several words\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "s = input(\"Enter some words, separated by whitespase: \")\n", | |
| "words = s.split()\n", | |
| "if words:\n", | |
| " print(\"We have several words\")\n", | |
| "else:\n", | |
| " print(\"We have no words!\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 18, | |
| "id": "hundred-precipitation", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 18, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool([1, 2])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 19, | |
| "id": "motivated-bench", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 19, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool([False])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 20, | |
| "id": "forced-vegetarian", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "False" | |
| ] | |
| }, | |
| "execution_count": 20, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "bool([])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 21, | |
| "id": "modern-natural", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "ZeroDivisionError", | |
| "evalue": "division by zero", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
| "\u001b[0;32m<ipython-input-21-9e1622b385b6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "1/0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 22, | |
| "id": "native-saskatchewan", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "x = \"Hello\" or (1/0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 23, | |
| "id": "latest-recognition", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'Hello'" | |
| ] | |
| }, | |
| "execution_count": 23, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "x" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 25, | |
| "id": "small-reminder", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter your name: Ilya\n", | |
| "Hello Ilya\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "default_name = \"Anonymous\"\n", | |
| "s = input(\"Enter your name: \")\n", | |
| "name = s or default_name\n", | |
| "print(\"Hello\", name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 26, | |
| "id": "interstate-italian", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Enter your name: \n", | |
| "Hello Anonymous\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "default_name = \"Anonymous\"\n", | |
| "s = input(\"Enter your name: \")\n", | |
| "if s:\n", | |
| " name = s\n", | |
| "else:\n", | |
| " name = default_name\n", | |
| "print(\"Hello\", name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 28, | |
| "id": "neutral-sharing", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello, World!\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(\"Hello\", \"World\", sep=\", \", end=\"!\\n\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 30, | |
| "id": "prompt-elements", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "5040" | |
| ] | |
| }, | |
| "execution_count": 30, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "n = 7\n", | |
| "f = 1\n", | |
| "for i in range(1, n + 1):\n", | |
| " f = f * i\n", | |
| "f" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 31, | |
| "id": "auburn-calvin", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def factorial(n):\n", | |
| " f = 1\n", | |
| " for i in range(1, n + 1):\n", | |
| " f = f * i\n", | |
| " return f" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 35, | |
| "id": "further-medication", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "5160" | |
| ] | |
| }, | |
| "execution_count": 35, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "factorial(7) + factorial(5)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 39, | |
| "id": "changing-queen", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "6\n", | |
| "100\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "f = 100\n", | |
| "def factorial(n):\n", | |
| " f = 1\n", | |
| " for i in range(1, n + 1):\n", | |
| " f = f * i\n", | |
| " return f\n", | |
| "\n", | |
| "print(factorial(3))\n", | |
| "print(f)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 40, | |
| "id": "charged-machinery", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from math import sqrt" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 41, | |
| "id": "eleven-volunteer", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "f = 100\n", | |
| "def show_f():\n", | |
| " print(f)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 42, | |
| "id": "fatty-bristol", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "100\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "show_f()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 43, | |
| "id": "illegal-season", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "15\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "f = 15\n", | |
| "show_f()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 44, | |
| "id": "advisory-reminder", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def show_a():\n", | |
| " print(a)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 45, | |
| "id": "animal-foundation", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "NameError", | |
| "evalue": "name 'a' 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-45-76387284371e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mshow_a\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;32m<ipython-input-44-222f542d61a1>\u001b[0m in \u001b[0;36mshow_a\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mshow_a\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\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 'a' is not defined" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "show_a()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 46, | |
| "id": "billion-booth", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "123\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 123\n", | |
| "show_a()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 52, | |
| "id": "faced-penalty", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "10" | |
| ] | |
| }, | |
| "execution_count": 52, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "a = 10\n", | |
| "def foo():\n", | |
| " # print(a)\n", | |
| " a = 12\n", | |
| "foo()\n", | |
| "a" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 50, | |
| "id": "regulated-decade", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[1, 2, 3, 100]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "my_list = [1, 2, 3]\n", | |
| "def add_element_to_my_list(x):\n", | |
| " my_list.append(x)\n", | |
| "add_element_to_my_list(100)\n", | |
| "print(my_list)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 55, | |
| "id": "entitled-ecuador", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Russian\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "language = \"English\"\n", | |
| "def set_language(new_language):\n", | |
| " global language\n", | |
| " language = new_language\n", | |
| "\n", | |
| "set_language(\"Russian\")\n", | |
| "print(language)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 56, | |
| "id": "focal-government", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def say_42():\n", | |
| " print(42)\n", | |
| "\n", | |
| "def return_42():\n", | |
| " return 42" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 57, | |
| "id": "sound-spectrum", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "42\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "say_42()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 58, | |
| "id": "periodic-virginia", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "42" | |
| ] | |
| }, | |
| "execution_count": 58, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "return_42()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 59, | |
| "id": "atmospheric-incidence", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "42\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "x = say_42()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 61, | |
| "id": "endless-survivor", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "None\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(x)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 63, | |
| "id": "sonic-bishop", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "x" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 65, | |
| "id": "banner-photographer", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "execution_count": 65, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "None == None" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 66, | |
| "id": "helpful-bathroom", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "False" | |
| ] | |
| }, | |
| "execution_count": 66, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "None == 1" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 68, | |
| "id": "infectious-tension", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "y = return_42()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 69, | |
| "id": "smooth-killing", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "42" | |
| ] | |
| }, | |
| "execution_count": 69, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 70, | |
| "id": "minor-adolescent", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def sum_3(x, y, z):\n", | |
| " return x + y + z" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 71, | |
| "id": "written-commercial", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "665" | |
| ] | |
| }, | |
| "execution_count": 71, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "sum_3(23, 100, 542)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 72, | |
| "id": "baking-chemistry", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def hello(first_name, last_name):\n", | |
| " print(\"Hello\", first_name, last_name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 73, | |
| "id": "resident-mortality", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Harry Potter\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Harry\", \"Potter\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 74, | |
| "id": "external-banner", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Harry Potter\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(first_name=\"Harry\", last_name=\"Potter\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 75, | |
| "id": "regulation-orchestra", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Harry Potter\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(last_name=\"Potter\", first_name=\"Harry\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 76, | |
| "id": "civilian-differential", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Harry Potter\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Harry\", last_name=\"Potter\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 77, | |
| "id": "material-albert", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "SyntaxError", | |
| "evalue": "positional argument follows keyword argument (<ipython-input-77-97ad54a0d341>, line 1)", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;36m File \u001b[0;32m\"<ipython-input-77-97ad54a0d341>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m hello(last_name=\"Potter\", \"Harry\")\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(last_name=\"Potter\", \"Harry\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 78, | |
| "id": "stainless-satisfaction", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def hello(first_name, last_name, title=\"Mr\"):\n", | |
| " print(\"Hello\", title, first_name, last_name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 79, | |
| "id": "ambient-logging", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Mr Harry Potter\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Harry\", \"Potter\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 80, | |
| "id": "indonesian-sodium", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Prof. Severus Snape\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Severus\", \"Snape\", \"Prof.\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 81, | |
| "id": "least-genesis", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Prof. Severus Snape\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Severus\", \"Snape\", title=\"Prof.\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 82, | |
| "id": "rising-mainstream", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def hello(first_name, last_name, title=\"Mr\"):\n", | |
| " \"\"\"\n", | |
| " Приветствует пользователя.\n", | |
| " \n", | |
| " Аргументы:\n", | |
| " \n", | |
| " first_name — имя пользователя\n", | |
| " last_name — фамилия пользователя\n", | |
| " title — обращение (по умолчанию \"Mr\")\n", | |
| " \"\"\"\n", | |
| " print(\"Hello\", title, first_name, last_name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 83, | |
| "id": "immune-truck", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from matplotlib.pyplot import plot" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 85, | |
| "id": "cross-potter", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "??plot" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 87, | |
| "id": "novel-purple", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "TypeError", | |
| "evalue": "hello() takes from 2 to 3 positional arguments but 4 were given", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
| "\u001b[0;32m<ipython-input-87-06d92906cafd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mhello\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Hello\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Harry\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Potter\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Mr\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;31mTypeError\u001b[0m: hello() takes from 2 to 3 positional arguments but 4 were given" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Hello\", \"Harry\", \"Potter\", \"Mr\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 86, | |
| "id": "fuzzy-builder", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "2 5 100 54 Hello\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(2, 5, 100, 54, \"Hello\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 92, | |
| "id": "particular-staff", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def foo(*args):\n", | |
| " print(type(args))\n", | |
| " print(args)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 93, | |
| "id": "vocal-fever", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "<class 'tuple'>\n", | |
| "(3, 4, 5, 100, 'Hello')\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "foo(3, 4, 5, 100, \"Hello\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 108, | |
| "id": "comfortable-criminal", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def hello(first_name, last_name, *middlenames, title, **kwargs):\n", | |
| " print(\"Hello\", title, first_name, end=\" \")\n", | |
| " for middlename in middlenames:\n", | |
| " print(middlename, end=\" \")\n", | |
| " print(last_name)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 102, | |
| "id": "north-being", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Prof. Albus Percival Wulfric Brian Dumbledore\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "hello(\"Albus\", \"Dumbledore\", \"Percival\", \"Wulfric\", \"Brian\", title=\"Prof.\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 103, | |
| "id": "accessory-jacket", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def sum_2d_vectors(u, v):\n", | |
| " return (u[0] + v[0], u[1] + v[1])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 105, | |
| "id": "gorgeous-justice", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(5, 7)" | |
| ] | |
| }, | |
| "execution_count": 105, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "sum_2d_vectors((1, 4), (4, 3))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 109, | |
| "id": "injured-excess", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "names = (\"Albus\", \"Percival\", \"Wulfric\", \"Dumbledore\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 110, | |
| "id": "relevant-adoption", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "('Albus', 'Percival', 'Wulfric', 'Dumbledore')\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(names)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 111, | |
| "id": "wrong-external", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Albus Percival Wulfric Dumbledore\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(\" \".join(names))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 112, | |
| "id": "digital-execution", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Albus Percival Wulfric Dumbledore\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(*names)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 113, | |
| "id": "curious-sally", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1 2 3\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(*[1, 2, 3])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 114, | |
| "id": "honest-motivation", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1 2 3\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "print(1, 2, 3)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 115, | |
| "id": "mechanical-cameroon", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def foo(x, y, z):\n", | |
| " print(\"x =\", x)\n", | |
| " print(\"y =\", y)\n", | |
| " print(\"z =\", z)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 116, | |
| "id": "greenhouse-auckland", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "point3d = (1, 5, 3)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 117, | |
| "id": "fiscal-official", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "TypeError", | |
| "evalue": "foo() missing 2 required positional arguments: 'y' and 'z'", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
| "\u001b[0;32m<ipython-input-117-bb93431d9ef7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfoo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpoint3d\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
| "\u001b[0;31mTypeError\u001b[0m: foo() missing 2 required positional arguments: 'y' and 'z'" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "foo(point3d)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 118, | |
| "id": "optional-lemon", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "x = 1\n", | |
| "y = 5\n", | |
| "z = 3\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "foo(*point3d)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 119, | |
| "id": "advance-pilot", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "x, y, z = [1, 2, 3]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 120, | |
| "id": "outstanding-crystal", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "1" | |
| ] | |
| }, | |
| "execution_count": 120, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "x" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 121, | |
| "id": "addressed-copyright", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "2" | |
| ] | |
| }, | |
| "execution_count": 121, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 122, | |
| "id": "impressive-prime", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "3" | |
| ] | |
| }, | |
| "execution_count": 122, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "z" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 124, | |
| "id": "dynamic-eugene", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "('Albus', 'Percival', 'Wulfric', 'Dumbledore')" | |
| ] | |
| }, | |
| "execution_count": 124, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "names" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 125, | |
| "id": "cleared-decade", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "first_name, *middle_names, last_name = names" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 126, | |
| "id": "affected-parts", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'Albus'" | |
| ] | |
| }, | |
| "execution_count": 126, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "first_name" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 127, | |
| "id": "special-sellers", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'Dumbledore'" | |
| ] | |
| }, | |
| "execution_count": 127, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "last_name" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 128, | |
| "id": "behavioral-envelope", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['Percival', 'Wulfric']" | |
| ] | |
| }, | |
| "execution_count": 128, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "middle_names" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 129, | |
| "id": "spare-lunch", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "first_name = names[0]\n", | |
| "last_name = names[-1]\n", | |
| "middle_names = names[1:-1]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 130, | |
| "id": "indie-header", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "('Percival', 'Wulfric')" | |
| ] | |
| }, | |
| "execution_count": 130, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "middle_names" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "sacred-secondary", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "gist": { | |
| "data": { | |
| "description": "Lesson05.ipynb", | |
| "public": false | |
| }, | |
| "id": "" | |
| }, | |
| "kernelspec": { | |
| "display_name": "Python 3.9 (system)", | |
| "language": "python", | |
| "name": "py39_system" | |
| }, | |
| "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.9.0" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment