Naming Conventions

The full text of this chapter, to read or revisit. To practise, do the exercises.

▶ Do the exercises

Exercise 1 — Naming convention

To keep things organized and consistent in the code, we use naming conventions for variables. Basically, these are rules created by developers so that variable names are clear and easy to understand.

In Python, we use snake_case for variable names: - descriptive name - all letters are lowercase - underscores between words - no special characters - no numbers at the beginning - name in english

For example: score_player, game_level, player_name.

Variables names in english / french

Because I'm French and this course was originally written in French, some variable names might be in French. Feel free to send me an email or report the question when you see one, thanks!

Exercise 2 — Variable creation following snake_case rules

Which of these is the correct and snake_case way to declare and assign a value to a variable in Python?

Options
• codemon_name = "Aquachu"
• Codémon_name = "Aquachu"
• codemon name = "Aquachu"
• codemon n@ame = "Aquachu"

Hint : Remember : snake_case, lowercase, no special characters, no numbers at the beginning, descriptive name in English.

Exercise 3 — Naming convention

Which of these variable names follows snake_case naming conventions?

Options
• codemon_type
• codemon type
• codemon-type
• codemon@type

Hint : Remember: snake_case, lowercase, no special characters, no numbers at the beginning, descriptive name in English.

Exercise 4 — Naming convention

Match each variable name on the left with it's issue about the naming convention on the right

Items to match
• Codemon_name
• codemon@name
• 1_codemon_name
• variable
Definitions
• First letter is uppercase
• Special character used
• Starts with a number
• Not descriptive enough
Back to the course