issue78:tuto_python
                Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| issue78:tuto_python [2014/03/11 18:14] – [1] frangi | issue78:tuto_python [2014/03/22 20:14] (Version actuelle) – fredphil91 | ||
|---|---|---|---|
| Ligne 24: | Ligne 24: | ||
| Ce mois-ci, je vais revisiter la commande d' | Ce mois-ci, je vais revisiter la commande d' | ||
| - | Puisque la syntaxe de la fonction print est différente entre Python 2.x et 3.x, nous allons les examiner séparément. Rappelez-vous, | + | Puisque la syntaxe de la fonction print est différente entre Python 2.x et 3.x, nous allons les examiner séparément. Rappelez-vous, | 
| - | >>> | + | >>> | 
| - | >>> | + | >>> | 
| - | et la sortie sera en gras, comme ceci: | + | et la sortie sera en gras, comme ceci : | 
| - | String | + | La chaine | 
| Python 2.x | Python 2.x | ||
| Ligne 51: | Ligne 51: | ||
| ** | ** | ||
| - | Bien sûr, vous vous souvenez que la syntaxe simple pour la fonction print en 2.x utilise la substitution de variable de %s ou %d pour les chaînes simples ou les nombres décimaux. Mais beaucoup d' | + | Bien sûr, vous vous souvenez que la syntaxe simple pour la fonction print en 2.x utilise la substitution de variable de %s ou %d pour les chaînes simples ou les nombres décimaux. Mais beaucoup d' | 
| - | >>> | + | >>> | 
| - | Your value is 004 | + | Votre valeur est 004 | 
| - | Dans ce cas, nous utilisons la commande de format ' | + | Dans ce cas, nous utilisons la commande de format ' | 
| >>> | >>> | ||
| Ligne 75: | Ligne 75: | ||
| Greetings Fred Farkel of Denver! | Greetings Fred Farkel of Denver! | ||
| - | ** | ||
| - | ** | ||
| The following table shows the various possible substitution keys and their meanings. | The following table shows the various possible substitution keys and their meanings. | ||
| + | ** | ||
| + | Ici, nous utilisons l' | ||
| + | |||
| + | Une autre chose que vous pourriez ne pas avoir réalisé est que vous pouvez utiliser les clés d'un dictionnaire dans le cadre de la commande format. | ||
| + | |||
| + | >>> | ||
| + | |||
| + | >>> | ||
| + | |||
| + | Bienvenue Fred Farkel de Denver! | ||
| + | |||
| + | Le tableau suivant présente les différentes clés de substitution possibles et leurs significations. | ||
| + | |||
| + | ** | ||
| Python 3.x | Python 3.x | ||
| Ligne 93: | Ligne 105: | ||
| The replacement fields are enclosed within curly brackets “{“ “}”. Anything outside of these are considered a literal and will be printed as is. In the first example, we have numbered the replacement fields 0 and 1. That tells Python to take the first (0) value and put it into the field {0} and so on. However, you don’t have to use any numbers at all. Using this option causes the first value to be places in the first set of brackets and so on. | The replacement fields are enclosed within curly brackets “{“ “}”. Anything outside of these are considered a literal and will be printed as is. In the first example, we have numbered the replacement fields 0 and 1. That tells Python to take the first (0) value and put it into the field {0} and so on. However, you don’t have to use any numbers at all. Using this option causes the first value to be places in the first set of brackets and so on. | ||
| - | ** | ||
| - | ==== 3 ==== | ||
| - | ** | ||
| >>> | >>> | ||
| This version of Python is 3.3.2 | This version of Python is 3.3.2 | ||
| + | ** | ||
| + | |||
| + | Python 3.x | ||
| + | |||
| + | Avec Python 3.x, nous avons beaucoup plus d' | ||
| + | |||
| + | Pour vous rafraîchir la mémoire, voici un exemple simple de la fonction print en 3.x. | ||
| + | |||
| + | >>> | ||
| + | Salut Python | ||
| + | |||
| + | >>> | ||
| + | Python est SUPER sympa ! | ||
| + | |||
| + | Les champs de remplacement sont enfermés dans des accolades " | ||
| + | |||
| + | >>> | ||
| + | Cette version de Python est 3.3.2 | ||
| + | |||
| + | |||
| + | ==== 3 ==== | ||
| + | ** | ||
| As they say on the TV ads, “BUT WAIT… THERE’S MORE”. If we wanted to do some inline formatting, we have the following options. | As they say on the TV ads, “BUT WAIT… THERE’S MORE”. If we wanted to do some inline formatting, we have the following options. | ||
| Ligne 116: | Ligne 147: | ||
| ** | ** | ||
| - | ==== 4 ==== | + | Comme ils le disent sur les publicités télévisées, | 
| + | |||
| + | :<x alignement à gauche avec une largeur de x | ||
| + | :>x alignement à droite avec une largeur de x | ||
| + | :^x alignement centré avec une largeur de x | ||
| + | |||
| + | Voici un exemple : | ||
| + | |||
| + | >>> | ||
| + | |A gauche | ||
| + | >>> | ||
| + | | A droite| | ||
| + | >>> | ||
| + | | | ||
| + | |||
| ** | ** | ||
| You can even specify a fill character along with the justification/ | You can even specify a fill character along with the justification/ | ||
| Ligne 140: | Ligne 186: | ||
| Well, that should give you enough food for thought for this month. I’ll see you at the start of the 5th year. | Well, that should give you enough food for thought for this month. I’ll see you at the start of the 5th year. | ||
| ** | ** | ||
| + | |||
| + | Vous pouvez même spécifier un caractère de remplissage avec la justification ou la largeur : | ||
| + | |||
| + | >>> | ||
| + | *****321.4 | ||
| + | |||
| + | Si vous avez besoin de formater une sortie de date ou d' | ||
| + | |||
| + | >>> | ||
| + | |||
| + | >>> | ||
| + | 29/10/13 | ||
| + | |||
| + | >>> | ||
| + | 10:45:01 | ||
| + | |||
| + | Afficher le séparateur des milliers en utilisant une virgule (ou tout autre caractère) est simple. | ||
| + | |||
| + | >>> | ||
| + | Voici un grand nombre 7.219.219.281 | ||
| + | |||
| + | Eh bien, cela devrait vous donner assez de nourriture pour la pensée pendant ce mois. Je vous revois au début de la 5e année. | ||
| + | |||
issue78/tuto_python.1394558072.txt.gz · Dernière modification : 2014/03/11 18:14 de frangi
                
                