{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Python Cours Accéléré\n", "\n", "S'il vous plaît noter que ce n'est pas censé être un cours complet de Python ou de la programmation en général, si vous n'avez aucune expérience en programmation, vous devriez probablement suivre mon autre cours: [Formation complète pour débutant](https://www.udemy.com/course/python-datascience/?referralCode=9DB381B321631A0703C2) à la place.\n", "\n", "**Ce notebook est juste une référence de code pour les vidéos, pas d'explications écrites ici**\n", "\n", "Ce notebook traitera des sujets suivants dans l'ordre:\n", "\n", "* Types de données (Data Types)\n", " * Nombres (int - float)\n", " * Chaînes de caractères (string)\n", " * Affichage (print)\n", " * Listes\n", " * Dictionnaires\n", " * Booléens\n", " * Tuples \n", " * Sets\n", "* Opérateurs de comparaison\n", "* Conditions if, elif et else\n", "* Boucles for (for loops)\n", "* Boucles while (while loops)\n", "* range()\n", "* Compréhension de liste (list comprehension)\n", "* Fonctions\n", "* Expressions lambda\n", "* map et filter\n", "* Méthodes\n", "____" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Types de Données\n", "\n", "### Nombres" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 + 1" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 * 3" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 / 2" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "16" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 ** 4" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "4 % 2" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "5 % 2" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "50" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(2 + 3) * (5 + 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Assignation de variable" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Ne peut pas commencer par un chiffre ou par des caractères spéciaux\n", "name_of_var = 2" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "x = 2\n", "y = 3" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "z = x + y" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### String" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'single quotes'" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'single quotes'" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'double quotes'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"double quotes\"" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\" wrap lot's of other quotes\"" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\" wrap lot's of other quotes\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Affichage" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "x = 'bonjour'" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'bonjour'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "bonjour\n" ] } ], "source": [ "print(x)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "num = 12\n", "name = 'Sam'" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mon nombre est: 12, et mon nom est: Sam\n" ] } ], "source": [ "print('Mon nombre est: {one}, et mon nom est: {two}'.format(one=num,two=name))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mon nombre est: 12, et mon nom est: Sam\n" ] } ], "source": [ "print('Mon nombre est: {}, et mon nom est: {}'.format(num,name))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Listes" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[1,2,3]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['hi', 1, [1, 2]]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "['hi',1,[1,2]]" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "my_list = ['a','b','c']" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "my_list.append('d')" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd']" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'a'" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list[0]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'b'" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list[1]" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['b', 'c', 'd']" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list[1:]" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a']" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list[:1]" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "my_list[0] = 'NEW'" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['NEW', 'b', 'c', 'd']" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_list" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "nest = [1,2,3,[4,5,['target']]]" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[4, 5, ['target']]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nest[3]" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['target']" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nest[3][2]" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'target'" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nest[3][2][0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dictionnaires" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "d = {'key1':'item1','key2':'item2'}" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'key1': 'item1', 'key2': 'item2'}" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'item1'" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d['key1']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Booléens" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "True" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "False" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tuples " ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "t = (1,2,3)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t[0]" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'tuple' object does not support item assignment", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'NEW'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" ] } ], "source": [ "t[0] = 'NEW'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Sets" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 3}" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{1,2,3}" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{1, 2, 3}" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{1,2,3,1,2,1,2,3,3,3,3,2,2,2,1,1,2}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Opérateurs de Comparaison" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 > 2" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 < 2" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 >= 1" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 <= 4" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 == 1" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'hi' == 'bye'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Opérateurs Logiques" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1 > 2) and (2 < 3)" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1 > 2) or (2 < 3)" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1 == 2) or (2 == 3) or (4 == 4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conditions if, elif et else" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Yep!\n" ] } ], "source": [ "if 1 < 2:\n", " print('Yep!')" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "yep!\n" ] } ], "source": [ "if 1 < 2:\n", " print('yep!')" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "first\n" ] } ], "source": [ "if 1 < 2:\n", " print('first')\n", "else:\n", " print('last')" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "last\n" ] } ], "source": [ "if 1 > 2:\n", " print('first')\n", "else:\n", " print('last')" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "middle\n" ] } ], "source": [ "if 1 == 2:\n", " print('first')\n", "elif 3 == 3:\n", " print('middle')\n", "else:\n", " print('Last')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Boucles for" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "seq = [1,2,3,4,5]" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "5\n" ] } ], "source": [ "for item in seq:\n", " print(item)" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Yep\n", "Yep\n", "Yep\n", "Yep\n", "Yep\n" ] } ], "source": [ "for item in seq:\n", " print('Yep')" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "4\n", "6\n", "8\n", "10\n" ] } ], "source": [ "for jelly in seq:\n", " print(jelly+jelly)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Boucles while" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "i est: 1\n", "i est: 2\n", "i est: 3\n", "i est: 4\n" ] } ], "source": [ "i = 1\n", "while i < 5:\n", " print('i est: {}'.format(i))\n", " i = i+1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## range()" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "range(0, 5)" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "range(5)" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "for i in range(5):\n", " print(i)" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4]" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Compréhension de liste" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "x = [1,2,3,4]" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 4, 9, 16]\n" ] } ], "source": [ "out = []\n", "for item in x:\n", " out.append(item**2)\n", "print(out)" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 4, 9, 16]" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[item**2 for item in x]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Fonctions" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [], "source": [ "def my_func(param1='default'):\n", " \"\"\"\n", " Docstring ou Documentation ici...\n", " \"\"\"\n", " print(param1)" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_func" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "default\n" ] } ], "source": [ "my_func()" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "new param\n" ] } ], "source": [ "my_func('new param')" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "new param\n" ] } ], "source": [ "my_func(param1='new param')" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "def square(x):\n", " return x**2" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [], "source": [ "out = square(2)" ] }, { "cell_type": "code", "execution_count": 78, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n" ] } ], "source": [ "print(out)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Expressions lambda" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [], "source": [ "def times2(var):\n", " return var*2" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "times2(2)" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(var)>" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lambda var: var*2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## map et filter" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [], "source": [ "seq = [1,2,3,4,5]" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map(times2,seq)" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 4, 6, 8, 10]" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(map(times2,seq))" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 4, 6, 8, 10]" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(map(lambda var: var*2,seq))" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "filter(lambda item: item%2 == 0,seq)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 4]" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(filter(lambda item: item%2 == 0,seq))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Méthodes" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [], "source": [ "st = 'hello mon nom est Sam'" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'hello mon nom est sam'" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st.lower()" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'HELLO MON NOM EST SAM'" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st.upper()" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['hello', 'mon', 'nom', 'est', 'Sam']" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "st.split()" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [], "source": [ "tweet = 'Go Sports! #Sports'" ] }, { "cell_type": "code", "execution_count": 93, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Go Sports! ', 'Sports']" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tweet.split('#')" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Sports'" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tweet.split('#')[1]" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'key1': 'item1', 'key2': 'item2'}" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['key1', 'key2'])" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.keys()" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_items([('key1', 'item1'), ('key2', 'item2')])" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d.items()" ] }, { "cell_type": "code", "execution_count": 98, "metadata": {}, "outputs": [], "source": [ "lst = [1,2,3]" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst.pop()" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2]" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lst" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'x' in [1,2,3]" ] }, { "cell_type": "code", "execution_count": 102, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'x' in ['x','y','z']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Bon Travail!" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.7" } }, "nbformat": 4, "nbformat_minor": 1 }