4.1.1

Identifiers

Test yourself

Identifiers

Identifiers are the names given to variables, constants, and subroutines.

Illustrative background for VariablesIllustrative background for Variables ?? "content

Variables

  • Variables should have lowercase names, with each word separated by an underscore. For example:
    • this_is_my_variable
    • user_money
  • Variable should also have descriptive names, for example user_money is much better than this_is_my_variable.
Illustrative background for ConstantsIllustrative background for Constants ?? "content

Constants

  • Constants should be named using the same rules as variables, but uppercase.
Illustrative background for SubroutinesIllustrative background for Subroutines ?? "content

Subroutines

  • Subroutines should have lowercase names, with each word separated by an underscore. For example:
    • calculate_sum()
    • get_user_id()
  • Subroutines should have descriptive names where possible.
Illustrative background for Global rulesIllustrative background for Global rules ?? "content

Global rules

  • In general, all identifiers should be descriptive.
  • Characters which might be confused should be avoided, for example:
    • 0 and O.
    • 1 and l (lower case L).

Jump to other topics

1Introduction to Python

2Data Structures

2.1Lists & Strings

2.2File Handling

3Modularity

3.1Subroutines

3.2Data Flow

4Good Practice

4.1Naming & Whitespace

4.2Comments

4.3Exceptions

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson