Programming: Getting started
Variable name and scope
Variable namesVariable names should be descriptive and explain what sort of values will be stored in the variable. The following rules need to be considered when naming variables:
Naming conventionsWe follow naming conventions to make code easier to read and maintain. In Python, you can use snake_case. In snake_case, all words are in lowercase only, and words are separated by an underscore character. Scope'Scope' refers to the visibility of variables. There are four types of scope in Python: local, enclosing, global and built-in. Most of the time, you will be using local variables. Local variables are only visible to, and can only be used in, the block of code in which they were declared. You will learn more about scope when you learn how to use functions. |