Skip to main content

Python Course by Google

Naming rules and conventions

命名規則與慣例

When assigning names to objects, programmers adhere to a set of rules and conventions which help to standardize code and make it more accessible to everyone. Here are some naming rules and conventions that you should know:

  • Names cannot contain spaces.

  • Names may be a mixture of upper and lower case characters.

  • Names can’t start with a number but may contain numbers after the first character.

  • Variable names and function names should be written in snake_case, which means that all letters are lowercase and words are separated using an underscore. 

  • Descriptive names are better than cryptic abbreviations because they help other programmers (and you) read and interpret your code. For example, student_name is better than sn. It may feel excessive when you write it, but when you return to your code you’ll find it much easier to understand.

 

 

Resources