Skip to content
Snippets Groups Projects
2_Types_simples.ipynb 16.8 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alessandro Cerioni's avatar
    Alessandro Cerioni committed
    {
     "cells": [
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "# Types de données simples"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "## Nombres entiers"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 1,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "int"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 1,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a = 1\n",
        "type(a)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 2,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "2"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 2,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a+1"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 3,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [],
       "source": [
        "b = 2"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 4,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "3"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 4,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a+b"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "## Nombres en virgule flottante"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 5,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "0.5"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 5,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a/2"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 6,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "float"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 6,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "type(a/2)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "division entière :"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 7,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "0"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 7,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a//2"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "## Booléens"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 8,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "False"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 8,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a == b"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 9,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 9,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "a != b"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 10,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "bool"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 10,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "type(a>0)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 11,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "name": "stdout",
         "output_type": "stream",
         "text": [
          "Cool!\n"
         ]
        }
       ],
       "source": [
        "if True:\n",
        "    print('Cool!')"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 12,
       "metadata": {},
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "outputs": [],
       "source": [
        "z = a==b"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Comment faire des contrôles sur le type ?"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 13,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 13,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "type(z) == bool"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 14,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 14,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "isinstance(z, bool)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "## Chaînes de caractères"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 15,
       "metadata": {},
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "outputs": [],
       "source": [
        "b = \"ceci est une chaîne de caractères\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 16,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'ceci est une chaîne de caractères'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 16,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "b"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 17,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "str"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 17,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "type(b)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 18,
       "metadata": {},
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "outputs": [],
       "source": [
        "c = \"\"\"\n",
        "Ceci est une châine de caractères\n",
        "sur plusieurs lignes\n",
        "\"\"\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 19,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'\\nCeci est une châine de caractères\\nsur plusieurs lignes\\n'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 19,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "c"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 20,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "name": "stdout",
         "output_type": "stream",
         "text": [
          "\n",
          "Ceci est une châine de caractères\n",
          "sur plusieurs lignes\n",
          "\n"
         ]
        }
       ],
       "source": [
        "print(c)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Opérations sur les chaînes de caractères"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 21,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'ceci est une chaîne de caractères !'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 21,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "b + \" !\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 22,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'!!!'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 22,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "\"!\"*3"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 23,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'!!!'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 23,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "3*\"!\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 24,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "33"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 24,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "len(b)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 25,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "['__add__',\n",
           " '__class__',\n",
           " '__contains__',\n",
           " '__delattr__',\n",
           " '__dir__',\n",
           " '__doc__',\n",
           " '__eq__',\n",
           " '__format__',\n",
           " '__ge__',\n",
           " '__getattribute__',\n",
           " '__getitem__',\n",
           " '__getnewargs__',\n",
           " '__gt__',\n",
           " '__hash__',\n",
           " '__init__',\n",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
           " '__init_subclass__',\n",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
           " '__iter__',\n",
           " '__le__',\n",
           " '__len__',\n",
           " '__lt__',\n",
           " '__mod__',\n",
           " '__mul__',\n",
           " '__ne__',\n",
           " '__new__',\n",
           " '__reduce__',\n",
           " '__reduce_ex__',\n",
           " '__repr__',\n",
           " '__rmod__',\n",
           " '__rmul__',\n",
           " '__setattr__',\n",
           " '__sizeof__',\n",
           " '__str__',\n",
           " '__subclasshook__',\n",
           " 'capitalize',\n",
           " 'casefold',\n",
           " 'center',\n",
           " 'count',\n",
           " 'encode',\n",
           " 'endswith',\n",
           " 'expandtabs',\n",
           " 'find',\n",
           " 'format',\n",
           " 'format_map',\n",
           " 'index',\n",
           " 'isalnum',\n",
           " 'isalpha',\n",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
           " 'isascii',\n",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
           " 'isdecimal',\n",
           " 'isdigit',\n",
           " 'isidentifier',\n",
           " 'islower',\n",
           " 'isnumeric',\n",
           " 'isprintable',\n",
           " 'isspace',\n",
           " 'istitle',\n",
           " 'isupper',\n",
           " 'join',\n",
           " 'ljust',\n",
           " 'lower',\n",
           " 'lstrip',\n",
           " 'maketrans',\n",
           " 'partition',\n",
           " 'replace',\n",
           " 'rfind',\n",
           " 'rindex',\n",
           " 'rjust',\n",
           " 'rpartition',\n",
           " 'rsplit',\n",
           " 'rstrip',\n",
           " 'split',\n",
           " 'splitlines',\n",
           " 'startswith',\n",
           " 'strip',\n",
           " 'swapcase',\n",
           " 'title',\n",
           " 'translate',\n",
           " 'upper',\n",
           " 'zfill']"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 25,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "dir(b)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 26,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'CECI EST UNE CHAÎNE DE CARACTÈRES'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 26,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "b.upper()"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 27,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "['ceci', 'est', 'une', 'chaîne', 'de', 'caractères']"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 27,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "b.split()"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 28,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'ceci, est, une, chaîne, de, caractères'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 28,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "\", \".join( b.split() )"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Formatage de chaînes de caractères"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 29,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'Oui, ceci est une chaîne de caractères!'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 29,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "\"Oui, %s!\" % (b)      # very old style"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 30,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'Oui, ceci est une chaîne de caractères!'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 30,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "\"Oui, {0}!\".format(b) # old style, Python 2.6+"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 31,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'Oui, ceci est une chaîne de caractères!'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 31,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "\"{0}, {1}!\".format(\"Oui\", b) "
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 32,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
           "'Oui, ceci est une chaîne de caractères!'"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 32,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "f\"Oui, {b}!\"          # new style, Python 3.6+"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 33,
       "metadata": {},
       "outputs": [],
       "source": [
        "my_num = 1.23456"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 34,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'Voici un numéro avec 3 chiffres décimaux: 1.235'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 34,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "f\"Voici un numéro avec 3 chiffres décimaux: {my_num:.3f}\""
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
        "Pour plus d'info, cf. https://pyformat.info/, https://realpython.com/python-f-strings/"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "## Conversions"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "N.B. : typage dynamique **fort**"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 35,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "ename": "TypeError",
         "evalue": "unsupported operand type(s) for +: 'int' and 'str'",
         "output_type": "error",
         "traceback": [
          "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
          "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
          "\u001b[0;32m<ipython-input-35-bd58363a63fc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \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",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
          "\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'"
         ]
        }
       ],
       "source": [
        "a + b"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 36,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "'1 est une chaîne de caractère'"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 36,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "str(a) + \" est une chaîne de caractère\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 37,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [],
       "source": [
        "c = \"10\""
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 38,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "11"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 38,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "int(c) + 1"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 39,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "False"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 39,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "bool(0)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 40,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 40,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "bool(1)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 41,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 41,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "bool(\"test\")"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 42,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 42,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "bool(3.14)"
       ]
      },
      {
       "cell_type": "code",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "execution_count": 43,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "False"
          ]
         },
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "execution_count": 43,
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "bool(0.0)"
       ]
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": []
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
      }
     ],
     "metadata": {
      "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",
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
       "version": "3.7.5"
    
    Alessandro Cerioni's avatar
    Alessandro Cerioni committed
      }
     },
     "nbformat": 4,
     "nbformat_minor": 2
    }