English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Python

Contrôle de flux Python

Fonctions en Python

Types de données en Python

Opérations de fichiers Python

Objets et classes Python

Dates et heures Python

Connaissances avancées Python

Manuel de référence Python

Mots-clés et identificateurs de Python

Dans ce tutoriel, vous découvrirez les mots-clés (mots réservés dans Python) et les identificateurs (noms de variables, fonctions, etc.).

mots-clés Python

les mots-clés sont des mots réservés dans Python.

Nous ne pouvons pas utiliser les mots-clés comme  nom de variablefonctionun nom ou tout autre identificateur. Ils sont utilisés pour définir la syntaxe et la structure du langage Python.

Dans Python, les mots-clés sont sensibles à la casse.

Python 3.7contient 33 des mots-clés. Ce nombre peut légèrement changer dans un certain temps.

tous les mots-clés doivent être en minuscules, sauf True, False et None. Voici la liste de tous les mots-clés.

les mots-clés de Python
Falseawaitelseimportpass
Nonebreakexceptinraise
Trueclassfinallyisreturn
andcontinueforlambdatry
asdeffromnonlocalwhile
assertdelglobalnotwith
asyncelififoryield

it may be difficult to view all keywords at once and try to understand their meanings.

If you want to view the list of all keywords, here isall keywordscompletelistand examples.

Python identifiers

Identifiers are the names given to entities such as classes, functions, and variables. They help distinguish one entity from another.

rules for writing identifiers

  1. Identifiers can be lowercase letters(a to z)or uppercase letters(A to Z)or numbers(0 to 9)or the combination of underscore (_) and myClass, var_1,var_name_1, print_this_to_screen are all valid.

  2. Identifiers cannot start with numbers.1variable is invalid, but variable1 is valid.

  3. keywords cannot be used as identifiers.

    >>> global = 1
      File "<interactive input>", line 1
        global = 1
               ^
    SyntaxError: invalid syntax
  4. We cannot use like@#$such as special symbols.

    >>> a@ = 0
      File "<interactive input>", line 1
        a@ = 0
         ^
    SyntaxError: invalid syntax
  5. Identifiers can be of any length.

things to remember

Python is Case sensitive language. This means that Variable and variable are two different variables. It is also recommended that meaningful identifiers be used in actual programming.

Although, c = 10 is also valid. However, it is recommended to use count = 10 It will look more meaningful, and it will also be easier to understand the purpose and meaning of the code even after a long period of time.

You can use underscores to separate multiple words for naming, for example: this_is_a_long_variable