Concept Flow - Naming rules and conventions
Start
Choose name
Check rules
Apply conventions
Use name
End
Rename
Choose name
Pick a name, check if it follows Python rules, then apply style conventions before using it.
var1 = 10 _var2 = 20 3var = 30 MyVar = 40 my_var = 50
| Step | Variable Name | Valid? | Reason | Convention Style |
|---|---|---|---|---|
| 1 | var1 | Yes | Starts with letter, contains letters and digits | lowercase with digits allowed |
| 2 | _var2 | Yes | Starts with underscore, allowed | leading underscore for internal use |
| 3 | 3var | No | Starts with digit, not allowed | N/A |
| 4 | MyVar | Yes | Starts with uppercase letter, allowed | PascalCase (class style) |
| 5 | my_var | Yes | Starts with letter, contains underscore | snake_case (recommended for variables) |
| Variable Name | Validity | Convention |
|---|---|---|
| var1 | Valid | lowercase with digits |
| _var2 | Valid | leading underscore |
| 3var | Invalid | starts with digit |
| MyVar | Valid | PascalCase |
| my_var | Valid | snake_case |
Python variable names must start with a letter or underscore, not a digit. Use lowercase with underscores (snake_case) for variables. PascalCase is for classes. Leading underscore means internal use. Avoid special characters and spaces.