diff --git a/notebooks/beginner/exercises/strings_exercise.ipynb b/notebooks/beginner/exercises/strings_exercise.ipynb index 38aee8b..4a406a4 100644 --- a/notebooks/beginner/exercises/strings_exercise.ipynb +++ b/notebooks/beginner/exercises/strings_exercise.ipynb @@ -10,14 +10,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "original = ' Python strings are COOL! '\n", - "lower_cased = original._____\n", - "stripped = ____.strip()\n", - "stripped_lower_cased = original._____._____" + "lower_cased = original.lower()\n", + "stripped = original.strip()\n", + "stripped_lower_cased = original.lower().strip()" ] }, { @@ -29,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "editable": false }, @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "editable": false }, @@ -61,12 +61,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Your implementation:\n", - "pretty = 'TODO'" + "pretty = ugly.strip().title()" ] }, { @@ -78,11 +78,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "editable": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pretty: Title Of My New Book\n" + ] + } + ], "source": [ "print('pretty: {}'.format(pretty))\n", "assert pretty == 'Title Of My New Book'" @@ -98,7 +106,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "editable": false }, @@ -111,25 +119,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Your implementation:\n", - "sentence = 'TODO'" + "sentence = 'Learning {} {} fun{}'.format(language, verb, punctuation)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "editable": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sentence: Learning Python is fun!\n" + ] + } + ], "source": [ "print('sentence: {}'.format(sentence))\n", "assert sentence == 'Learning Python is fun!'" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -148,7 +171,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/notebooks/beginner/notebooks/classes.ipynb b/notebooks/beginner/notebooks/classes.ipynb index b39b340..f9325af 100644 --- a/notebooks/beginner/notebooks/classes.ipynb +++ b/notebooks/beginner/notebooks/classes.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -23,9 +23,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my_instance: <__main__.MyFirstClass object at 0x7fa35c572c88>\n", + "type: \n", + "my_instance.name: John Doe\n" + ] + } + ], "source": [ "my_instance = MyFirstClass('John Doe')\n", "print('my_instance: {}'.format(my_instance))\n", @@ -43,9 +53,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Alice!\n" + ] + } + ], "source": [ "alice = MyFirstClass(name='Alice')\n", "alice.greet()" @@ -61,9 +79,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "creating instance of Example\n", + "Now we are inside __init__\n", + "instance created\n" + ] + } + ], "source": [ "class Example:\n", " def __init__(self):\n", @@ -83,9 +111,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "abc 123\n" + ] + } + ], "source": [ "class Example:\n", " def __init__(self, var1, var2):\n", @@ -110,9 +146,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is the string presentation of jack: Person: Jack\n" + ] + } + ], "source": [ "class Person:\n", " def __init__(self, name, age):\n", @@ -136,9 +180,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "instance_variable: foo, name: Modified name, description: Just an example of a simple class\n", + "instance_variable: bar, name: Modified name, description: Just an example of a simple class\n" + ] + } + ], "source": [ "class Example:\n", " # These are class variables\n", @@ -180,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -204,9 +257,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15\n" + ] + }, + { + "ename": "AttributeError", + "evalue": "can't set attribute", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mexample_person\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;31m# But not this:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0mexample_person\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m16\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: can't set attribute" + ] + } + ], "source": [ "class Person:\n", " def __init__(self, age):\n", @@ -220,7 +292,7 @@ "# Now you can do this:\n", "print(example_person.age)\n", "# But not this:\n", - "#example_person.age = 16" + "# example_person.age = 16" ] }, { @@ -232,9 +304,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Happy bday for 16 years old!\n" + ] + } + ], "source": [ "class Person:\n", " def __init__(self, age):\n", @@ -261,7 +341,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -287,9 +367,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "wof wof\n", + "Dog's favorite food is beef\n", + "Hello, I am an animal\n", + "Cat's favorite food is fish\n" + ] + } + ], "source": [ "dog = Dog()\n", "dog.greet()\n", @@ -299,6 +390,13 @@ "cat.greet()\n", "print(\"Cat's favorite food is {}\".format(cat.favorite_food))" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -317,7 +415,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/notebooks/beginner/notebooks/conditionals.ipynb b/notebooks/beginner/notebooks/conditionals.ipynb index 3850f20..ed4a13e 100644 --- a/notebooks/beginner/notebooks/conditionals.ipynb +++ b/notebooks/beginner/notebooks/conditionals.ipynb @@ -23,18 +23,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "type of True and False: \n" + ] + } + ], "source": [ "print('type of True and False: {}'.format(type(True)))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0: False, 1: True\n", + "empty list: False, list with values: True\n", + "empty dict: False, dict with values: True\n" + ] + } + ], "source": [ "print('0: {}, 1: {}'.format(bool(0), bool(1)))\n", "print('empty list: {}, list with values: {}'.format(bool([]), bool(['woop'])))\n", @@ -50,9 +68,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 == 0: False\n", + "1 != 0: True\n", + "1 > 0: True\n", + "1 > 1: False\n", + "1 < 0: False\n", + "1 < 1: False\n", + "1 >= 0: True\n", + "1 >= 1: True\n", + "1 <= 0: False\n", + "1 <= 1: True\n" + ] + } + ], "source": [ "print('1 == 0: {}'.format(1 == 0))\n", "print('1 != 0: {}'.format(1 != 0))\n", @@ -75,9 +110,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 <= 2 <= 3: True\n" + ] + } + ], "source": [ "print('1 <= 2 <= 3: {}'.format(1 <= 2 <= 3))" ] @@ -91,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -103,9 +146,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python and java are both cool: False\n", + "secret_value and python_is_cool: True\n" + ] + } + ], "source": [ "print('Python and java are both cool: {}'.format(python_is_cool and java_is_cool))\n", "print('secret_value and python_is_cool: {}'.format(secret_value and python_is_cool))" @@ -113,9 +165,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python or java is cool: True\n", + "1 >= 1.1 or 2 < float(\"1.4\"): False\n" + ] + } + ], "source": [ "print('Python or java is cool: {}'.format(python_is_cool or java_is_cool))\n", "print('1 >= 1.1 or 2 < float(\"1.4\"): {}'.format(1 >= 1.1 or 2 < float('1.4')))" @@ -123,9 +184,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Java is not cool: True\n" + ] + } + ], "source": [ "print('Java is not cool: {}'.format(not java_is_cool))" ] @@ -139,9 +208,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], "source": [ "print(bool(not java_is_cool or secret_value and python_is_cool or empty_list))\n", "print(bool(not (java_is_cool or secret_value and python_is_cool or empty_list)))" @@ -285,7 +363,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/notebooks/beginner/notebooks/debugging.ipynb b/notebooks/beginner/notebooks/debugging.ipynb index af2e669..cf05174 100644 --- a/notebooks/beginner/notebooks/debugging.ipynb +++ b/notebooks/beginner/notebooks/debugging.ipynb @@ -103,7 +103,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/notebooks/beginner/notebooks/dictionaries.ipynb b/notebooks/beginner/notebooks/dictionaries.ipynb index f1b4f39..f3ab8e9 100644 --- a/notebooks/beginner/notebooks/dictionaries.ipynb +++ b/notebooks/beginner/notebooks/dictionaries.ipynb @@ -10,9 +10,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict: {}, type: \n" + ] + } + ], "source": [ "my_empty_dict = {} # alternative: my_empty_dict = dict()\n", "print('dict: {}, type: {}'.format(my_empty_dict, type(my_empty_dict)))" @@ -27,9 +35,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'value1': 1.6, 'value2': 10, 'name': 'John Doe'}\n", + "{'value1': 1.6, 'value2': 10, 'name': 'John Doe'}\n", + "equal: True\n", + "length: 3\n" + ] + } + ], "source": [ "dict1 = {'value1': 1.6, 'value2': 10, 'name': 'John Doe'}\n", "dict2 = dict(value1=1.6, value2=10, name='John Doe')\n", @@ -50,9 +69,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "keys: dict_keys(['value1', 'value2', 'name'])\n", + "values: dict_values([1.6, 10, 'John Doe'])\n", + "items: dict_items([('value1', 1.6), ('value2', 10), ('name', 'John Doe')])\n" + ] + } + ], "source": [ "print('keys: {}'.format(dict1.keys()))\n", "print('values: {}'.format(dict1.values()))\n", @@ -68,9 +97,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'key1': 'new value', 'key2': 99}\n", + "value of key1: new value\n" + ] + } + ], "source": [ "my_dict = {}\n", "my_dict['key1'] = 'value1'\n", @@ -89,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -105,9 +143,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'key1': 'value1', 'key2': 99}\n", + "my_key is not in {'key1': 'value1', 'key2': 99}\n" + ] + } + ], "source": [ "my_dict = {'key1': 'value1', 'key2': 99, 'keyX': 'valueX'}\n", "del my_dict['keyX']\n", @@ -130,9 +177,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my_dict: {'ham': 'good', 'carrot': 'super tasty', 'sausage': 'best ever'}\n", + "other: {'ham': 'good', 'carrot': 'super tasty', 'sausage': 'best ever'}\n", + "equal: True\n" + ] + } + ], "source": [ "my_dict = {'ham': 'good', 'carrot': 'semi good'}\n", "my_other_dict = my_dict\n", @@ -151,9 +208,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "my_dict: {'ham': 'good', 'carrot': 'semi good'}\n", + "other: {'ham': 'good', 'carrot': 'semi good', 'beer': 'decent'}\n", + "equal: False\n" + ] + } + ], "source": [ "my_dict = {'ham': 'good', 'carrot': 'semi good'}\n", "my_other_dict = dict(my_dict)\n", @@ -173,9 +240,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d: None\n", + "d: my default value\n" + ] + } + ], "source": [ "my_dict = {'a': 1, 'b': 2, 'c': 3}\n", "d = my_dict.get('d')\n", @@ -194,9 +270,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict before pops: {'food': 'ham', 'drink': 'beer', 'sport': 'football'}\n", + "food: ham\n", + "dict after popping food: {'drink': 'beer', 'sport': 'football'}\n", + "food again: default value for food\n", + "dict after popping food again: {'drink': 'beer', 'sport': 'football'}\n" + ] + } + ], "source": [ "my_dict = dict(food='ham', drink='beer', sport='football')\n", "print('dict before pops: {}'.format(my_dict))\n", @@ -220,9 +308,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a: 1\n", + "d: my default value\n", + "my_dict: {'a': 1, 'b': 2, 'c': 3, 'd': 'my default value'}\n" + ] + } + ], "source": [ "my_dict = {'a': 1, 'b': 2, 'c': 3}\n", "a = my_dict.setdefault('a', 'my default value')\n", @@ -240,9 +338,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'a': 1, 'b': 2, 'c': 3}\n", + "{'a': 1, 'b': 2, 'c': 4}\n" + ] + } + ], "source": [ "dict1 = {'a': 1, 'b': 2}\n", "dict2 = {'c': 3}\n", @@ -271,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -287,13 +394,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'my key': ['Python', 'is', 'still', 'cool']}\n" + ] + } + ], "source": [ "good_dict = {'my key': ['Python', 'is', 'still', 'cool']}\n", "print(good_dict)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -312,7 +434,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.0" } }, "nbformat": 4, diff --git a/notebooks/beginner/notebooks/strings.ipynb b/notebooks/beginner/notebooks/strings.ipynb index c87bba4..7df87c0 100644 --- a/notebooks/beginner/notebooks/strings.ipynb +++ b/notebooks/beginner/notebooks/strings.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -18,27 +18,60 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Python is my favorite programming language!'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "my_string" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(my_string)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "43" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "len(my_string)" ] @@ -52,9 +85,20 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Lorem ipsum dolor sit amet, consectetur adipiscing elit.Pellentesque eget tincidunt felis. Ut ac vestibulum est.In sed ipsum sit amet sapien scelerisque bibendum. Sed sagittis purus eu diam fermentum pellentesque.'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "long_story = ('Lorem ipsum dolor sit amet, consectetur adipiscing elit.' \n", " 'Pellentesque eget tincidunt felis. Ut ac vestibulum est.' \n", @@ -79,9 +123,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method_descriptor:\n", + "\n", + "replace(...)\n", + " S.replace(old, new[, count]) -> str\n", + " \n", + " Return a copy of S with all occurrences of substring\n", + " old replaced by new. If the optional argument count is\n", + " given, only the first count occurrences are replaced.\n", + "\n" + ] + } + ], "source": [ "help(str.replace)" ] @@ -95,9 +155,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python is my favorite programming language!\n" + ] + } + ], "source": [ "my_string.replace('a', '?')\n", "print(my_string)" @@ -112,9 +180,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python will be my favorite programming language!\n" + ] + } + ], "source": [ "my_modified_string = my_string.replace('is', 'will be')\n", "print(my_modified_string)" @@ -129,9 +205,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Python is cool\n" + ] + } + ], "source": [ "secret = '{} is cool'.format('Python')\n", "print(secret)" @@ -139,9 +223,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My name is John Doe, you can call me John.\n", + "My name is John Doe, you can call me John.\n" + ] + } + ], "source": [ "print('My name is {} {}, you can call me {}.'.format('John', 'Doe', 'John'))\n", "# is the same as:\n", @@ -157,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -169,9 +262,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Some cool python libraries: pandas, numpy, requests\n" + ] + } + ], "source": [ "print('Some cool python libraries: {}'.format(cool_python_libs))" ] @@ -185,9 +286,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Some cool python libraries: pandas, numpy, requests\n", + "Some cool python libraries: pandas, numpy, requests\n" + ] + } + ], "source": [ "cool_python_libs = pandas + ', ' + numpy + ', ' + requests\n", "print('Some cool python libraries: {}'.format(cool_python_libs))\n", @@ -207,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -216,27 +326,60 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'PYTHON HACKER'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "mixed_case.upper()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'python hacker'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "mixed_case.lower()" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Python Hacker'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "mixed_case.title()" ] @@ -250,9 +393,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ugly: \n", + " \t Some story to tell \n", + "stripped: Some story to tell\n" + ] + } + ], "source": [ "ugly_formatted = ' \\n \\t Some story to tell '\n", "stripped = ugly_formatted.strip()\n", @@ -270,9 +423,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['three', 'different', 'words']\n" + ] + } + ], "source": [ "sentence = 'three different words'\n", "words = sentence.split()\n", @@ -281,18 +442,37 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(words)" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['01001', '101101', '11100000']\n" + ] + } + ], "source": [ "secret_binary_data = '01001,101101,11100000'\n", "binaries = secret_binary_data.split(',')\n", @@ -308,9 +488,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this looks good\n" + ] + } + ], "source": [ "ugly_mixed_case = ' ThIS LooKs BAd '\n", "pretty = ugly_mixed_case.strip().lower().replace('bad', 'good')\n", @@ -326,9 +514,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this looks bad\n" + ] + } + ], "source": [ "pretty = ugly_mixed_case.replace('bad', 'good').strip().lower()\n", "print(pretty)" @@ -343,9 +539,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First line\n", + "Second line\n" + ] + } + ], "source": [ "two_lines = 'First line\\nSecond line'\n", "print(two_lines)" @@ -353,13 +558,63 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\tThis will be indented\n" + ] + } + ], "source": [ "indented = '\\tThis will be indented'\n", "print(indented)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conclusion\n", + "* new to me:writing long string: \n", + "s =('a'\n", + " 'b'\n", + " 'c')\n", + "* 首字母大写\n", + "str.title()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]\r\n", + " [-D [bind_address:]port] [-E log_file] [-e escape_char]\r\n", + " [-F configfile] [-I pkcs11] [-i identity_file] [-L address]\r\n", + " [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\r\n", + " [-Q query_option] [-R address] [-S ctl_path] [-W host:port]\r\n", + " [-w local_tun[:remote_tun]] [user@]hostname [command]\r\n" + ] + } + ], + "source": [ + "!ssh" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -378,7 +633,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.6.8" } }, "nbformat": 4,