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

Tutorial Básico do Python

Controle de Fluxo do Python

Função do Python

Tipos de dados do Python

Operações de Arquivos do Python

Objetos e Classes do Python

Data e Hora do Python

Conhecimento Avançado do Python

Manual de Referência do Python

Palavras-chave e identificadores do Python

Neste tutorial, você aprenderá palavras-chave (palavras reservadas no Python) e identificadores (nomes de variáveis, funções, etc.).

palavras-chave do Python

palavras-chave são palavras reservadas no Python.

não podemos usar palavras-chave como  nome da variável,funçãonomes ou qualquer outro identificador. Eles são usados para definir a sintaxe e a estrutura da linguagem Python.

nas palavras-chave do Python, a diferenciação de maiúsculas e minúsculas é discriminada.

Python 3.7com 33 palavras-chave. Este número pode variar ligeiramente em um período de tempo.

todas as palavras-chave devem ser minúsculas, exceto True, False e None. A seguir, está listado todas as palavras-chave.

palavras-chave do 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 names given to entities such as classes, functions, and variables. It helps distinguish one entity from another.

Rules for writing identifiers

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

  2. Identifiers cannot start with a number.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!.,@,#,$,%and such 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 Variable and variable are two different variables. Also, it is recommended that meaningful identifiers be used in actual programming.

Although, c = 10 is also valid. But using count = 10 It will be more meaningful, and it will be easier to understand its function and meaning even if you look at the code after a long period of time.

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